#include <bits/stdc++.h>
using namespace std;
const int N = 25, M = 100;
int h[N], e[M], ne[M], w[M], idx;
int num[N];
int cnt[N];
int r[N];
int dist[N];
bool st[N];
void add(int a, int b, int c)
{
e[idx] = b, w[idx] = c, ne[idx] = h[a], h[a] = idx ++;
}
void build(int c)
{
memset(h, -1, sizeof h);
idx = 0;
// 0 <= xi <= num[i]
for (int i = 1; i <= 24; i ++)
{
add(i - 1, i, 0);
add(i, i - 1, -num[i]);
}
//xi - 7 + xi - 6 + …… xi >= ri
for (int i = 8; i <= 24; i ++) add(i - 8, i, r[i]);
for (int i = 1; i <= 7; i ++) add(i + 16, i, -c + r[i]);
add(0, 24, c), add(24, 0, -c);
}
bool spfa(int c)
{
build(c);
int q[N], tt = 0, hh = 0;
memset(dist, -0x3f, sizeof dist);
memset(st, 0, sizeof st);
memset(cnt, 0, sizeof cnt);
q[tt ++] = 0;
st[0] = true;
dist[0] = 0;
while (hh != tt)
{
int t = q[hh ++];
if (hh == N) hh = 0;
st[t] = false;
for (int i = h[t]; ~i; i = ne[i])
{
int j = e[i];
if (dist[j] < dist[t] + w[i])
{
dist[j] = dist[t] + w[i];
cnt[j] = cnt[t] + 1;
if (cnt[j] >= 25) return false;
if (!st[j])
{
q[tt ++] = j;
if (tt == N) tt = 0;
st[j] = true;
}
}
}
}
return true;
}
int main(void)
{
int t;
cin >> t;
while (t --)
{
for (int i = 1; i <= 24; i ++)
cin >> r[i];
int n;
cin >> n;
memset(num, 0, sizeof num);
for (int i = 0; i < n; i ++)
{
int x;
cin >> x;
num[x + 1] ++;
}
bool ok = false;
for (int i = 0; i <= 1000; i ++)
{
if (spfa(i))
{
cout << i << endl;
ok = true;
break;
}
}
if (!ok) puts("No Solution");
}
return 0;
}