#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template <class T>
void read(T &);
template <class T>
void write(const T &);

typedef long long ll;
typedef unsigned long long ull;
typedef const long long &cll;
typedef const int &ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::abs;
using std::max;
using std::min;

const int N = 200005;

int n, m;

int main() {
  read(n), read(m);
  if (m == 0) {
    for (int i = 1; i <= n; ++i) {
      write(2 * i), SP, write(2 * i + 1), EL;
    }
    return 0;
  }
  if (m > 0) {
    if (m >= n - 1) {
      puts("-1");
      return 0;
    }
    write(1), SP, write(2 * m + 4), EL;
    for (int i = 1; i <= m + 1; ++i) {
      write(2 * i), SP, write(2 * i + 1), EL;
    }
    for (int i = m + 3; i <= n; ++i) {
      write(2 * i + 4), SP, write(2 * i + 5), EL;
    }
  } else {
    puts("-1");
  }
  return 0;
}

template <class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template <class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}

typedef long long ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
long long extGcd(long long a, long long b, long long &p, long long &q) {
    if (b == 0) { 
        p = 1, q = 0; 
        return a; 
    }
    long long d = extGcd(b, a % b, q, p);
    q -= a / b * p;
    return d;
}

pair<long long, long long> ChineseRem(const vector<long long> &vr, const vector<long long> &vm) {
    if (vr.empty() || vm.empty()) return make_pair(0, 1);
    long long R = vr[0], M = vm[0];
    for (int i = 1; i < (int)vr.size(); ++i) {
        long long p, q, r = vr[i], m = vm[i];
        if (M < m) swap(M, m), swap(R, r); // prevent overflow
        long long d = extGcd(M, m, p, q); // p is inv of M/d (mod. m/d)
        if ((r - R) % d != 0) return make_pair(0, -1);
        long long md = m / d;
        long long tmp = (r - R) / d % md * p % md;
        R += M * tmp, M *= md;
    }
    R %= M;
    if (R < 0) R += M;
    return make_pair(R, M);
}
int main() {
    ll t;
    std::cin >> t;
    for (int iiii = 0; iiii < t; iiii++) {
        ll x,y,p,q;
        std::cin >> x>>y>>p>>q;
        ll ans = 1e18+1e+17;
        for (ll i = 0; i < y; i++) {
            for (ll j = 0; j < q; j++) {
                // if(i==0&&j==0)continue;
                auto [r,m]  = ChineseRem({x+i,p+j},{2*x+2*y, p+q});
                // std::cout << r<<" "<<m <<" "<<iiii<< std::endl;
                if(r==0&&m==-1)continue;
                // std::cout << r<<" :" << std::endl;
                ans = min(ans,r);
            }
        }
        if(ans==1e18+1e17){
            std::cout << "infinity" << std::endl;
            continue;
        }
        std::cout << ans << std::endl;
    }
}