#include <bits/stdc++.h>
#define SIZE 1005
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main()
{
	int n;
	scanf("%d",&n);
	int t=1;
	while(t<n) t<<=1;
	for(int i=0;i<n;i++)
	{
		int a=i*2;
		int b=i*2+1;
		for(int j=11;j>=0;j--)
		{
			if(a>=n&&(a>>j&1)) a^=1<<j;
			if(b>=n&&(b>>j&1)) b^=1<<j;
		}
		printf("%d %d\n",a+1,b+1);
	}
}
		
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define autoitr(x,it) for(auto it = x.rbegin(); it != x.rend(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

const ll N = 20;
long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }
inline long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
inline long long normalize(long long x, long long mod) { x %= mod; if (x < 0) x += mod; return x; }
struct GCD_type { long long x, y, d; };
GCD_type ex_GCD(long long a, long long b)
{
    if (b == 0) return {1, 0, a};
    GCD_type pom = ex_GCD(b, a % b);
    return {pom.y, pom.x - a / b * pom.y, pom.d};
}
ll testCases;
ll fun(ll t, ll a[], ll n[])
{
    ll lcm, ans;
    for(ll i=1;i<=t;i++) normalize(a[i], n[i]);
    ans = a[1];
    lcm = n[1];
    for(ll i = 2; i <= t; i++)
    {
        auto pom = ex_GCD(lcm, n[i]);
        ll x1 = pom.x;
        ll d = pom.d;
        if((a[i] - ans) % d != 0) return LLONG_MAX;
        ans = normalize(ans + x1 * (a[i] - ans) / d % (n[i] / d) * lcm, lcm * n[i] / d);
        lcm = LCM(lcm, n[i]); // you can save time by replacing above lcm * n[i] /d by lcm = lcm * n[i] / d
    }
    return ans;
}
 

int main()
{
  FAST/**/
  
  ll t;
  cin>>t;
  
  while(t--)
  {
      ll x,y,p,q;
      cin>>x>>y>>p>>q;
      
      ll ans = LLONG_MAX;
      
      for(ll r1=p;r1<=p+q-1;r1++)   
            for(ll r2=x;r2<=x+y-1;r2++)
            {
                ll r[3], m[3];
                r[1] = r1, m[1] = p+q;
                r[2] = r2, m[2] = 2*(x+y);
                ll temp = __gcd(m[1], m[2]);
                if(abs(r1-r2)%temp != 0)
                        continue;
                ans = min(ans, fun(2, r, m));        
            }
       if(ans != LLONG_MAX)        
            cout<<ans<<'\n';        
       else cout<<"infinity\n";        
  }
  
  return 0;
}
   
   
 