import java.util.Scanner; public class Main { static int fun(Scanner sc) { int n, m; int res = -1; int k = 0; n = sc.nextInt();// n个杯子 m = sc.nextInt();// m次操作 boolean[] a = new boolean[n]; boolean[] v = new boolean[n]; for (int i = 0; i < m; i++) { int o, x; o = sc.nextInt(); x = sc.nextInt(); if (res != -1) continue; if (o == 1) { if (a[x - 1] == false) { a[x - 1] = true; k++; if (k == n) { res = i + 1; } } } else {// o==2 if (v[x - 1] == false) {// 防止重复分析 v[x - 1] = true; if (a[x - 1] == true) { res = i + 1; } else { for (int j = 0; j < n; j++) { a[j] = true; } a[x - 1] = false; k = n - 1; } } } } return res; } public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); n = sc.nextInt(); for (int i = 0; i < n; i++) { int res = fun(sc); System.out.println(res); } sc.close(); } }