#include <iostream>
#include <vector>
using namespace std;
int main () {
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int k = 0, res = -1;
int n, m;
cin >> n >> m;
vector<bool> a(n + 1, false);
for (int j = 1; j <= m; ++j) {
int t, x;
cin >> t >> x;
if (t == 1) {
if (a[x] == false) {
a[x] = true;
k++;
}
}
if (t == 2) {
for (int i = 1; i <= n; ++i) {
if (i == x) {
continue;
} else {
if (a[i] == false) {
a[i] = true;
k++;
}
}
}
}
if (k == n) {
res = j;
break;
}
}
cout << res << endl;
}
return 0;
}