#include <iostream>
#include <algorithm>
using namespace std;
int Solution()
{
    int n, sum = 0, L[5] = {0}, m, M, W[5][10] = {0}, le, P, res = 0;
    for (int i = 0; i < 6; i++)
    {
        cin >> n;
        sum += n;
        for (int j = 0; j < n; j++)
        {
            cin >> m;
            L[m]++;
        }
    }
    cin >> M;
    int ww;
    for (int i = 0; i < M; i++)
    {
        cin >> le >> P;
        for (int j = 1; j <= P; j++)
        {
            cin >> ww;
            if (ww > W[le][j])
                W[le][j] = ww;
            if ((j + 1 > P) && P < 7)
                for (int k = j + 1; k <= 7; k++)
                    W[le][k] = W[le][k - 1];
        }
    }
    for (int i = 0; i <= L[4]; i++)
    {
        for (int j = 0; j <= (sum - L[1] - L[2] - i); j++)
        {
            for (int k = 0; k <= (sum - L[1] - (i + j)); k++)
            {
                for (int s = 0; s <= (sum - (i + j + k)); s++)
                {
                    int a, b, c, d;
                    if (i > 7)
                        a = 7;
                    else
                        a = i;
                    if (j > 7)
                        b = 7;
                    else
                        b = j;
                    if (k > 7)
                        c = 7;
                    else
                        c = k;
                    if (s > 7)
                        d = 7;
                    else
                        d = s;
                    res = max(res, W[4][a] + W[3][b] + W[2][c] + W[1][d]);
                }
            }
        }
    }
    return res;
}
int main()
{
    cout << Solution();
    return 0;
}
