#include <bits/stdc++.h>
using namespace std;
int calc(int* a) {
  int ans = 0;
  for (int i = 0; i < (3); i++) {
    if (a[i]) {
      ans++;
      a[i]--;
    }
  }
  if (a[0] == 1 and a[1] == 1 and a[2] > 1) {
    ans++;
    a[0]--;
    a[2]--;
  }
  for (int i = 0; i < (3); i++) {
    if (a[i] and a[(i + 1) % 3]) {
      ans++;
      a[i]--;
      a[(i + 1) % 3]--;
    }
  }
  if (a[0] and a[1] and a[2]) ans++;
  return ans;
}
int main() {
  if (0) printf("*debug mode*\n");
  int n;
  cin >> n;
  for (int _ = 0; _ < (n); _++) {
    int a[3];
    for (int& x : a) {
      cin >> x;
      x = min(x, 4);
    }
    printf("%d\n", calc(a));
  }
}
