#include <bits/stdc++.h>
using namespace std;
struct camel {
  int k, l, r;
};
bool comp(camel a, camel b) { return a.l - a.r > b.l - b.r; }
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    camel line[n];
    int x = 0, y = 0;
    for (__typeof(n) i = 0; i < n; i++) {
      cin >> line[i].k >> line[i].l >> line[i].r;
      if (line[i].l > line[i].r)
        x++;
      else
        y++;
    }
    sort(line, line + n, comp);
    int ans = 0;
    cout << ans << endl;
  }
  return 0;
}
