#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long
LL abss (LL A)
{
if (A > 0) return A;
else return - A;
}
LL dist (LL x1, LL y1, LL x2, LL y2)
{
return abss (x1 - x2) + (LL) abss (y1 - y2);
}
int main()
{
freopen ("portal3.in", "r", stdin);
freopen ("portal3.out", "w", stdout);
int T;
scanf ("%d", &T);
while (T --)
{
LL N, M;
scanf ("%lld %lld", &N, &M);
LL x1, y1, x2, y2, c1;
LL x3, y3, x4, y4, c2;
LL x5, y5, x6, y6, c3;
scanf ("%lld %lld %lld %lld %lld", &x1, &y1, &x2, &y2, &c1);
scanf ("%lld %lld %lld %lld %lld", &x3, &y3, &x4, &y4, &c2);
scanf ("%lld %lld %lld %lld %lld", &x5, &y5, &x6, &y6, &c3);
LL p1 = dist (0, 0, N, M);
LL p2 = dist (0, 0, x1, y1) + c1 + dist (x2, y2, N, M);
LL p3 = dist (0, 0, x3, y3) + c2 + dist (x4, y4, N, M);
LL p4 = dist (0, 0, x5, y5) + c3 + dist (x6, y6, N, M);
LL p5 = dist (0, 0, x1, y1) + c1 + dist (x2, y2, x3, y3) + c2 + dist (x4, y4, N, M);
LL p6 = dist (0, 0, x1, y1) + c1 + dist (x2, y2, x5, y5) + c3 + dist (x6, y6, N, M);
LL p7 = dist (0, 0, x3, y3) + c2 + dist (x4, y4, x5, y5) + c3 + dist (x6, y6, N, M);
LL p8 = dist (0, 0, x1, y1) + c1 + dist (x2, y2, x3, y3) + c2 + dist (x4, y4, x5, y5) + c3 + dist (x6, y6, N, M);
LL sol = p1;
sol = min (sol, p2);
sol = min (sol, p3);
sol = min (sol, p4);
sol = min (sol, p5);
sol = min (sol, p6);
sol = min (sol, p7);
sol = min (sol, p8);
printf ("%lld\n", sol);
}
return 0;
}