#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int i;
    int ol_cnt = 0;
    int cnt1 = 0;
    int cnt0 = 0;
    for (i = 0; i < n; i++) {
      string s;
      int j;
      cin >> s;
      for (j = 0; j < s.length(); j++) {
        if (s[j] == '1') {
          cnt1++;
        } else {
          cnt0++;
        }
      }
      if (s.length() % 2 == 1) ol_cnt++;
    }
    if (ol_cnt == 0) {
      if (cnt1 % 2 == 1 || cnt0 % 2 == 1) {
        cout << n - 1 << endl;
        continue;
      } else {
        cout << n << endl;
        continue;
      }
    } else if (ol_cnt == n) {
      if (n % 2 == 1) {
        if (cnt1 % 2 == 1 && cnt0 % 2 == 1) {
          cout << n - 1 << endl;
          continue;
        } else if (cnt1 % 2 == 0 && cnt0 % 2 == 0) {
          cout << n - 1 << endl;
          continue;
        } else {
          cout << n << endl;
          continue;
        }
      } else {
        if ((cnt1 % 2) + (cnt0 % 2) == 1) {
          cout << n - 1 << endl;
          continue;
        } else {
          cout << n << endl;
          continue;
        }
      }
    } else {
      cout << n << endl;
      continue;
    }
  }
  return 0;
}
