import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int num = scn.nextInt();
while(num-->0){
int a = scn.nextInt(), b = scn.nextInt() , c = scn.nextInt();
for(int i=b;;i++){
if((i-a)%7 == 0 && (i+b)%11 == 0 && (i-c)%17 == 0){
System.out.println(i);
break;
}
}
}
}
}