#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 6;
const double EPS = 1e-8;
double a[10][10];
int solve(bool l[], double ans[], const int &n)
{
    int res = 0, r = 0;
    for (int i = 0; i < n; ++i) l[i] = false;
    for (int i = 0; i < n; ++i)
    {
        for (int j = r; j < n; ++j)
            if (fabs(a[j][i]) > EPS)
            {
                for (int k = i; k <= n; ++k) swap(a[j][k], a[r][k]);
                break;
            }
        if (fabs(a[r][i]) < EPS)
        {
            ++res;
            continue;
        }
        for (int j = 0; j < n; ++j)
            if (j != r && fabs(a[j][i]) > EPS)
            {
                double tmp = a[j][i] / a[r][i];
                for (int k = i; k <= n; ++k) a[j][k] -= tmp * a[r][k];
            }
        l[i] = true, ++r;
    }
    for (int i = 0; i < n; ++i)
        if (l[i])
            for (int j = 0; j < n; ++j)
                if (fabs(a[j][i]) > 0) ans[i] = a[j][n] / a[j][i];
    return res;
}
int main()
{
    int T, Q;
    scanf("%d", &T);
    while (T--)
    {
        int x1, y1, x2, y2, x3, y3;
        int x4, y4, x5, y5, x6, y6;
        scanf("%d%d%d%d%d%d", &x1, &y1, &x2, &y2, &x3, &y3);
        scanf("%d%d%d%d%d%d", &x4, &y4, &x5, &y5, &x6, &y6);
        bool l[MAXN];
        double ans[MAXN];
        memset(l, 0, sizeof l);
        memset(ans, 0, sizeof ans);
        memset(a, 0, sizeof a);
        a[0][0] = x1;
        a[0][2] = y1;
        a[0][6] = x4;
        a[1][1] = x1;
        a[1][3] = y1;
        a[1][6] = y4;

        a[2][0] = x2;
        a[2][2] = y2;
        a[2][6] = x5;
        a[3][1] = x2;
        a[3][3] = y2;
        a[3][6] = y5;

        a[4][0] = x3;
        a[4][2] = y3;
        a[4][6] = x6;
        a[5][1] = x3;
        a[5][3] = y3;
        a[5][6] = y6;
        solve(l, ans, MAXN);
        for (int i = 0; i < MAXN; i++)
            printf("%c %d %.4lf\n", 'a' + i, l[i], ans[i]);
        scanf("%d", &Q);
        while (Q--)
        {
            int x, y;
            scanf("%d%d", &x, &y);
            printf("%.2lf %.2lf\n", ans[0] * x + ans[2] * y, ans[1] * x + ans[3] * y);
        }
    }
    return 0;
}
