// SHGAME Solution. Written by Sergey Kulik #include #include #include using namespace std; int n, m, i, j, k, kx[(1 << 20) + 10], t, Tn; long long ret, ret1; int main (int argc, char * const argv[]) { scanf("%d", &Tn); while (Tn--) { scanf("%d %d", &n, &m); ret = 0; for(i = 0; i < (1 << 20); i++) kx[i] = 0; for(i = 1; i <= m; i++) ++kx[(i - 1) ^ (m - i)]; // calculating all possible L XOR R for(i = 1; i <= n; i++) { t = (i - 1) ^ (n - i); // now we get some U XOR D ret += m - kx[t]; // add the number of suitable pairs from L XOR R list } printf("%lld\n", ret); } return 0; }