import java.util.*; import java.io.*; import java.text.*; //Solution Credits: Taranpreet Singh class Editorial{ //SOLUTION BEGIN int B = 32; long[][][][] dp = new long[B][B][B][]; void solve(int TC) throws Exception{ //CLeared DP array for(int i = 0; i< B; i++) for(int j = 0; j< B; j++) for(int k =0; k< B; k++) dp[i][j][k] = new long[]{-1,-1}; long a = nl(), b = nl(), c = nl(); pn(ans(0,bit(a), bit(b),0, c)); } //bit = bit :P, a = Number of bits of A yet to be used, b = Number of bits of B yet to be used, cf = carry forward, c is same as given in input. long ans(int bit, int a, int b, int cf, long c){ //Impossible case, Number of bits available cannot be negative if(a<0 || b<0)return 0; //Base case, Reached 32nd bit. if(bit==B)return (a==0 && b==0 && cf==0)?1:0; //If answer for this state already calculated. if(dp[bit][a][b][cf]!=-1)return dp[bit][a][b][cf]; //Current bit of c is 0 or 1 int x = (c&(1l<0?1:0; long ans = 0; //If cf is same as required bit, either bit is placed in both numbers, or none of the number. //If bit isn't used in any number, carry is 0 always. If bit is used in both numbers, carry is 1. if(cf==x)ans+=ans(bit+1,a,b,0,c)+ans(bit+1,a-1,b-1,1,c); //If cf is different, we need one of either A or B to have current bit 1, and other one should have bit 0. //Carry forward is 1, if cf is 1, otherwise 0. if(cf%2!=x)ans+=ans(bit+1, a-1,b,(cf+1)/2, c)+ans(bit+1,a,b-1,(cf+1)/2, c); return dp[bit][a][b][cf] = ans; } //SOLUTION ENDS long mod = (long)1e9+7, IINF = (long)1e17; final int MAX = (int)1e6+1, INF = (int)2e9, root = 3; DecimalFormat df = new DecimalFormat("0.000000000000"); double PI = 3.1415926535897932384626433832792884197169399375105820974944, eps = 1e-8; static boolean multipleTC = true, memory = false; FastReader in;PrintWriter out; void run() throws Exception{ in = new FastReader(); out = new PrintWriter(System.out); int T = (multipleTC)?ni():1; //Solution Credits: Taranpreet Singh for(int i = 1; i<= T; i++)solve(i); out.flush(); out.close(); } public static void main(String[] args) throws Exception{ if(memory)new Thread(null, new Runnable() {public void run(){try{new Editorial().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start(); else new Editorial().run(); } long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);} int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);} int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));} void p(Object o){out.print(o);} void pn(Object o){out.println(o);} void pni(Object o){out.println(o);out.flush();} String n(){return in.next();} String nln(){return in.nextLine();} int ni(){return Integer.parseInt(in.next());} long nl(){return Long.parseLong(in.next());} double nd(){return Double.parseDouble(in.next());} class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } public FastReader(String s) throws Exception{ br = new BufferedReader(new FileReader(s)); } String next(){ while (st == null || !st.hasMoreElements()){ try{ st = new StringTokenizer(br.readLine()); }catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } String nextLine(){ String str = ""; try{ str = br.readLine(); }catch (IOException e){ e.printStackTrace(); } return str; } } }