#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
#include "debug.h"
#else
#define debug(...)
#endif
#define int long long
#define oo LLONG_MAX >> 2
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define pep_Guardiola        \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
using namespace std;
void io()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
}


struct Node {
    int mx = -oo;
    int place = -1;
} NEUTRAL;

struct SegTree {
  int size;
  vector<Node> tree;

  SegTree(int n) {
    size = 1;
    while (size < n)
      size *= 2;
    tree.resize(2 * size);
  }

  Node merage(const Node &a, const Node &b) {
    Node res;
    if(a.mx >= b.mx){
        res = a;
    }else{
        res = b;
    }
    return res;
  }
  void build(vector<int> &a, int x, int lx, int rx) {
    if (rx - lx == 1) {
      if (lx < a.size()) {
       tree[x].place = lx; 
      }
      return;
    }
    int m = (lx + rx) / 2;
    build(a, 2 * x + 1, lx, m);
    build(a, 2 * x + 2, m, rx);
    tree[x] = merage(tree[2 * x + 1], tree[2 * x + 2]);
  }

  

  void update(int i, int v, int x, int lx, int rx) {
    if (rx - lx == 1) {
        tree[x].mx += v;
      return;
    }
    int m = (lx + rx) / 2;
    if (i < m)
      update(i, v, 2 * x + 1, lx, m);
    else
      update(i, v, 2 * x + 2, m, rx);
    tree[x] = merage(tree[2 * x + 1], tree[2 * x + 2]);
  }

  // zero based Range Query [l,r)
  Node query(int l, int r, int x, int lx, int rx)
  {
      if (lx >= r || rx <= l) return NEUTRAL;
      if (lx >= l && rx <= r) return tree[x];
      int m = (lx + rx)/2;
      return merage(query(l, r, 2*x+1, lx, m),query(l, r, 2*x+2, m, rx));
  }

  

  void build(vector<int> &a) { build(a, 0, 0, size); }
  void update(int i, int v) { update(i, v, 0, 0, size);}
  Node query(int l, int r) { return query(l, r, 0, 0, size); }
};

void Guardiola()
{
    int n,q;
    cin >> n >> q;
    vector<int> a(n+2);
    SegTree st(n+2);
    st.build(a);
    int last = 1;
    for(int i = 1 ;i <= q;i++){
        int id , v;
        cin >> id >> v;
        int prev = st.query(1,n+1).place;
        st.update(id , v);
        int cur = st.query(1,n+1).place;
        if(cur != prev) last = i;
    }
    cout << last << endl;
}

signed main()
{
    pep_Guardiola;
    io();
    int t = 1;
    cin >> t;
    while (t--)
        Guardiola();
    return 0;
}