#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    int k = 0;
    cin >> a >> b >> c;
    if (a == 0)
      cout << 0 << endl;
    else if (b == 0)
      cout << 0 << endl;
    else if (c == 0)
      cout << 0 << endl;
    else {
      if (a >= 3) {
        k += 3;
      }
      if (b >= 3) {
        k += 3;
      }
      if (c >= 3) {
        k += 3;
      }
      cout << k << endl;
    }
  }
  return 0;
}
