// Arup Guha
// 12/5/2015
// Solution to Fall 2015 UCF HS Online Contest Problem: Forest Fairies

import java.util.*;

public class fairies {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=0; loop<numCases; loop++) {

			// Read in the range.
			long low = stdin.nextLong();
			long high = stdin.nextLong();

			// Note: The only Catalan numbers that are odd are perfect powers of 2 minus 1.

			// Just look at bit counts to determine number of odd Catalan values in range.
			int lowBits = Long.toBinaryString(low).length();
			int highBits = Long.toBinaryString(high).length();
			int nextBits = Long.toBinaryString(high+1).length();

			// Only special case for bit counts.
			if (low == 0) lowBits = 0;

			// Count the number of odd Catalan numbers in range.
			int numOdd = highBits - lowBits;
			if (nextBits != highBits) numOdd++;

			// This formula works...
			System.out.println(2-numOdd%2);
		}
	}
}