#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
bool mp[20][20];
int d[4][2] = {{1, 0}, {0, -1}, {-1, 0}, {0, 1}};
void fil(int x, int y)
{
    mp[x][y] = true;
    for (int i = 0; i < 4; i++)
        if (!mp[x + d[i][0]][y + d[i][1]])
            fil(x + d[i][0], y + d[i][1]);
}
int main()
{
    int T, x11, y11, x12, y12, x21, y21, x22, y22;
    scanf("%d", &T);
    while (T--)
    {
        scanf("%d%d%d%d%d%d%d%d", &x11, &y11, &x12, &y12, &x21, &y21, &x22, &y22);
        int a[] = {x11, y11, x12, y12, x21, y21, x22, y22};
        sort(a, a + 8);
        int l = unique(a, a + 8) - a;
        x11 = (lower_bound(a, a + l, x11) - a + 1) << 1;
        y11 = (lower_bound(a, a + l, y11) - a + 1) << 1;
        x12 = (lower_bound(a, a + l, x12) - a + 1) << 1;
        y12 = (lower_bound(a, a + l, y12) - a + 1) << 1;
        x21 = (lower_bound(a, a + l, x21) - a + 1) << 1;
        y21 = (lower_bound(a, a + l, y21) - a + 1) << 1;
        x22 = (lower_bound(a, a + l, x22) - a + 1) << 1;
        y22 = (lower_bound(a, a + l, y22) - a + 1) << 1;
        CLR(mp);
        for (int i = x11; i <= x12; i++) mp[i][y11] = mp[i][y12] = true;
        for (int i = y11; i <= y12; i++) mp[x11][i] = mp[x12][i] = true;
        for (int i = x21; i <= x22; i++) mp[i][y21] = mp[i][y22] = true;
        for (int i = y21; i <= y22; i++) mp[x21][i] = mp[x22][i] = true;
        for (int i = 0; i < 20; i++)
            mp[0][i] = mp[19][i] = mp[i][0] = mp[i][19] = true;
        int cnt = 0;
        for (int i = 0; i < 20; i++)
            for (int j = 0; j < 20; j++)
                if (!mp[i][j])
                    fil(i, j), cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}