#include #include #include #include #include #include #define inf 0x3f3f3f3f #define maxv 10005 #define maxe 10005 using namespace std; int a[105]; int cnt; int get(int n) { return lower_bound(a,a+cnt,n)-a; } int dis[20][20]; const int MOD = 1e9+7; int main() { int T; int n,m,s,t; int t1,t2; int a1,a2,a3; int b1,b2,b3; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); cnt = 0; scanf("%d%d",&a1,&b1); a[cnt++] = a1; a[cnt++] = b1; scanf("%d%d",&a2,&b2); a[cnt++] = a2; a[cnt++] = b2; scanf("%d%d",&a3,&b3); a[cnt++] = a3; a[cnt++] = b3; sort(a,a+cnt); cnt = unique(a,a+cnt)-a; for(int i = 0;i < cnt;i++) for(int j = 0;j < cnt;j++) dis[i][j] = abs(a[i]-a[j]); t1 = get(a1); t2 = get(b1); dis[t1][t2] = dis[t2][t1] = min(dis[t1][t2],1); t1 = get(a2); t2 = get(b2); dis[t1][t2] = dis[t2][t1] = min(dis[t1][t2],1); t1 = get(a3); t2 = get(b3); dis[t1][t2] = dis[t2][t1] = min(dis[t1][t2],1); for(int k = 0;k < cnt;k++) for(int i = 0;i < cnt;i++) for(int j = 0;j < cnt;j++) dis[i][j] = min(dis[i][j],dis[i][k]+dis[k][j]); long long ans = 0; for(int k = 1;k <= m;k++) { scanf("%d%d",&s,&t); int tmp = abs(s-t); for(int i = 0;i < cnt;i++) for(int j = 0;j < cnt;j++) { tmp = min(tmp,abs(a[i]-s) + abs(a[j]-t) + dis[i][j]); } ans = (ans + (long long)tmp*k)%MOD; } printf("%d\n",(int)ans); } return 0; }