#include <bits/stdc++.h>
const long long int inf = (1e9 + 3);
const int M97 = ((int)1e9 + 7);
using namespace std;
long long int i, j, k;
void solve() {
  int n;
  cin >> n >> k;
  vector<int> chord_id(n << 1 | 1);
  int id = 0;
  for (i = 0; i < k; i++) {
    int u, v;
    cin >> u >> v;
    chord_id[u] = chord_id[v] = ++id;
  }
  vector<int> remaining_pts;
  for (i = 1; i < (int)chord_id.size(); i++)
    if (!chord_id[i]) remaining_pts.push_back(i);
  int sz = remaining_pts.size();
  sz >>= 1;
  for (i = 0; i < sz; i++)
    chord_id[remaining_pts[i]] = chord_id[remaining_pts[i + sz]] = ++id;
  bitset<128> b;
  long long int ans = 0;
  for (i = 1; i < (n << 1 | 1); i++) {
    b = 0;
    b[chord_id[i]] = 1;
    j = i % (n << 1) + 1;
    while (b[chord_id[i]])
      b[chord_id[j]] = b[chord_id[j]] ^ 1, j = j % (n << 1) + 1;
    ans += b.count();
  }
  ans >>= 2;
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
