#include <bits/stdc++.h>
using namespace std;
int main() {
  int t, a, b, c;
  cin >> t;
  while (t--) {
    int res = 0;
    cin >> a >> b >> c;
    if (a > 4) a = 4;
    if (b > 4) b = 4;
    if (c > 4) c = 4;
    int arr[3] = {a, b, c};
    int i1, i2, i3, i4, i5;
    i1 = count(arr, arr + 3, 0);
    i2 = count(arr, arr + 3, 1);
    i3 = count(arr, arr + 3, 2);
    i4 = count(arr, arr + 3, 3);
    i5 = count(arr, arr + 3, 4);
    if (i1 == 1) {
      res = 2;
      if (i2 == 0) {
        res++;
      }
    } else if (i1 == 2) {
      res = 1;
    } else if (i1 == 3) {
      res = 0;
    } else {
      res = 3;
      if (i2 == 1) {
        res++;
      } else if (i2 == 2) {
        res = 3;
      } else if (i2 == 3) {
        res = 3;
      } else {
        if (i3 == 1) {
          res += 2;
        } else if (i3 == 2) {
          res += 2;
        } else if (i3 == 3) {
          res++;
        } else {
          if (i4 == 1) {
            res += 3;
          } else if (i4 == 2) {
            res += 3;
          } else if (i4 == 3) {
            res += 3;
          } else {
            res = 7;
          }
        }
      }
    }
    cout << res << endl;
  }
  return 0;
}
