#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t;
  cin >> t;
  while (t--) {
    int n, p = 0, q = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
      long long int a, b;
      cin >> a >> b;
      int sum = 0;
      for (sum = 0; a > 0; sum += a % 10, a /= 10)
        ;
      sum;
      int sum1 = 0;
      for (sum1 = 0; b > 0; sum1 += b % 10, b /= 10)
        ;
      sum1;
      if (sum > sum1) {
        p++;
      } else if (sum1 > sum) {
        q++;
      }
    }
    if (p > q) {
      cout << "0"
           << " " << p << "\n";
    } else if (q > p) {
      cout << "1"
           << " " << q << "\n";
    } else {
      cout << "2"
           << " " << p << "\n";
    }
  }
  return 0;
}
