#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
#define LL long long
LL dist (int x1, int y1, int x2, int y2)
{
return abs (x1 - x2) + (LL) abs (y1 - y2);
}
int main()
{
freopen ("portal3.in", "r", stdin);
freopen ("portal3.out", "w", stdout);
int T;
scanf ("%d", &T);
while (T --)
{
int N, M;
scanf ("%d %d", &N, &M);
int x1, y1, x2, y2, c1;
int x3, y3, x4, y4, c2;
int x5, y5, x6, y6, c3;
scanf ("%d %d %d %d %d", &x1, &y1, &x2, &y2, &c1);
scanf ("%d %d %d %d %d", &x3, &y3, &x4, &y4, &c2);
scanf ("%d %d %d %d %d", &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;
}