/*
* @problem: ICPC16F
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <limits.h>
#include <vector>
#include <map>
#include <bitset>
#include <string>
#include <iterator>
#include <set>
#include <utility>
#include <queue>
#include <numeric>
#include <functional>
#include <ctype.h>
#include <stack>
#include <algorithm>
#include <cstdlib>
#define MAX 100100
#define mod 1000000007LL
#define bitcnt(x) __builtin_popcountll(x)
#define MS0(x) memset(x, 0, sizeof(x))
#define MS1(x) memset(x, -1, sizeof(x))
#define ll long long int
#define mp(x, y) make_pair(x, y)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define in(x) scanf("%lld", &x)
#define ind(x) scanf("%d", &x)
#define ins(x) scanf("%s", x)
#define pr(x) printf("%lld\n", x)
#define prd(x) printf("%d\n", x)
#define pi acos(-1.0)
#define ff first
#define ss second
using namespace std;
int n, m, d, D, inL[110], inR[110];
bool vis[110][110];
vector<pii> edge;
int main() {
#ifdef LOCAL_PROJECT
freopen("../input.txt", "r", stdin);
freopen("../output1.txt", "w", stdout);
#endif
// ios_base::sync_with_stdio(0);
// cin.tie(0);
int t;
ind(t);
while (t--) {
int M;
edge.clear();
priority_queue<pii, vector<pii>, greater<pii> > q;
MS0(inL);
MS0(inR);
MS0(vis);
ind(n);
ind(m);
ind(d);
ind(D);
M = m;
//cerr << n << " " << m << " " << d << " " << D << endl;
if ((m < (d * n)) || (m > (D * n))) {
printf("-1\n");
continue;
}
int c = m / n;
bool flag = 0;
for (int i = 1; i <= n && m > 0; i++) {
while(!q.empty())
q.pop();
for (int j = 1; j <= n; j++)
q.push(mp(inR[j], j));
while(inL[i] < c && !q.empty() && m > 0) {
pii cur = q.top();
q.pop();
if(vis[i][cur.ss] || inR[i] == c)
continue;
edge.push_back(mp(i, cur.ss));
inR[cur.ss]++;
vis[i][cur.ss] = 1;
inL[i]++;
m--;
}
}
for (int i = 1; i <= n && m > 0; i++) {
int c = 0;
while(!q.empty())
q.pop();
for (int j = 1; j <= n; j++)
q.push(mp(inR[j], j));
while(inL[i] < D && !q.empty() && m > 0) {
pii cur = q.top();
q.pop();
if(vis[i][cur.ss] || inR[cur.ss] == D)
continue;
edge.push_back(mp(i, cur.ss));
inR[cur.ss]++;
vis[i][cur.ss] = 1;
inL[i]++;
m--;
}
}
for (int i = 1; i <= n; i++) {
//cout << in[i] << " ";
if (inL[i] < d || inL[i] > D || inR[i] < d || inR[i] > D) {
flag = 1;
}
}
//cout << endl;
if (m != 0 || flag) {
printf("-1\n");
continue;
}
/*
The below line is an extra output for checker function only.
It was not added in the submission during the contest.
*/
cout << n << " " << M << " " << d << " " << D << endl;
for (int i = 0; i < edge.size(); i++) {
printf("%d %d\n", edge[i].ff, edge[i].ss);
}
}
return 0;
}
LyoKKiBAcHJvYmxlbTogSUNQQzE2RgoqLwoKI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGlvbWFuaXA+CiNpbmNsdWRlIDxjbWF0aD4KI2luY2x1ZGUgPGxpbWl0cy5oPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8Yml0c2V0PgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8aXRlcmF0b3I+CiNpbmNsdWRlIDxzZXQ+CiNpbmNsdWRlIDx1dGlsaXR5PgojaW5jbHVkZSA8cXVldWU+CiNpbmNsdWRlIDxudW1lcmljPgojaW5jbHVkZSA8ZnVuY3Rpb25hbD4KI2luY2x1ZGUgPGN0eXBlLmg+CiNpbmNsdWRlIDxzdGFjaz4KI2luY2x1ZGUgPGFsZ29yaXRobT4KI2luY2x1ZGUgPGNzdGRsaWI+CiNkZWZpbmUgTUFYIDEwMDEwMAojZGVmaW5lIG1vZCAxMDAwMDAwMDA3TEwKI2RlZmluZSBiaXRjbnQoeCkgX19idWlsdGluX3BvcGNvdW50bGwoeCkKI2RlZmluZSBNUzAoeC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