#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1e9 + 7;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
const int N = 30;
int dp[N][2][2];
int x, y;
int f(int len, int ex, int ey)
{
if (len == N)
return 1;
if (dp[len][ex][ey] != -1)
return dp[len][ex][ey];
dp[len][ex][ey] = 0;
int btx = ((x >> (N - len - 1) & 1);
int bty = ((y >> (N - len - 1) & 1);
FOR (bx, 0, 2)
{
if (ex && bx > btx)
continue;
int nex = ex && bx == btx;
FOR (by, 0, 2)
{
if (ey && by > bty)
continue;
if (ey == ex && ey == 1)
continue;
int ney = ey && by == bty;
add(dp[len][ex][ey], f(len + 1, nex, ney));
}
}
return dp[len][ex][ey];
}
void solve()
{
FOR (i, 0, N) FOR (j, 0, 2) FOR (k, 0, 2) dp[i][j][k] = -1;
cin >> x >> y;
int res = 0;
FOR (i, 0, )
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}