#include #include using namespace std; int abs(int x){ if (x<0) return -x; return x; } int ha[5],n,a[10],b[10],x,y,ans,T,m; bool use[5]; void dfs(int cur){ int tmp=0,np=x; for (int i=1;i3) return; for (int i=1;i<=3;i++){ if (!use[i]){ use[i]=true; ha[cur]=i; dfs(cur+1); ha[cur]=-i; dfs(cur+1); use[i]=false; } } } #define mod 1000000007 int main(){ #ifdef YJQ_LOCAL freopen(".in","r",stdin); freopen(".out","w",stdout); freopen("2.log","w",stderr); #endif scanf("%d",&T); while(T--){ long long ANS=0; scanf("%d%d",&n,&m); scanf("%d%d%d%d%d%d",&a[1],&b[1],&a[2],&b[2],&a[3],&b[3]); for (int i=1;i<=m;i++){ scanf("%d%d",&x,&y); ans=0x3f3f3f3f; dfs(1); ANS=(ANS+(long long)i*ans) % mod; } printf("%I64d\n",ANS); } }