#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
using namespace std;
typedef long long ll;
const int N = 3e5 + 5;
const ll maxn = 1e5 + 5;
struct Node
{
ll a, b, c, d;
} p;
vector<Node> vec[65];
ll vis[65];
ll dfs(ll u, ll a, ll b, ll c, ll d, ll now)
{
if (u == now + 1)
{
return (100 + a) * (100 + b) * (100 + c) * (100 + d);
}
ll n = vec[u].size();
ll ans = 0;
for (ll i = 0; i < n; i++)
{
p = vec[u][i];
ans = max(ans, dfs(u + 1, a + p.a, b + p.b, c + p.c, d + p.d, now));
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int t;
ll ans = 1;
for (int i = 0; i < 16; i++)
ans *= 3;
cout << ans << endl;
cin >> t;
while (t--)
{
ll n, k, cnt = 0;
cin >> n >> k;
for (ll i = 1; i <= n; i++)
vec[i].clear(), vis[i] = 0;
for (ll i = 0; i < n; i++)
{
ll kind, a, b, c, d;
cin >> kind >> a >> b >> c >> d;
if (!vis[kind])
vis[kind] = ++cnt;
vec[vis[kind]].push_back({a, b, c, d});
}
cout << dfs(1, 0, 0, 0, 0, cnt) << endl;
}
}