intmain(){ int t; scanf("%d", &t); while (t--) { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < 17; ++i) { a[n + i] = 1 << i; } n += 17; memset(vis, 0, sizeof vis); q = queue<int>(); q.push(0); vis[0] = true; len[0] = 0; while (!q.empty()) { int k = q.front(); q.pop(); for (int i = 0; i < n; ++i) { int x = k ^ a[i]; if (vis[x]) { continue; } len[x] = len[k] + 1; vis[x] = true; q.push(x); } } LL ans = 0; for (int i = 1; i <= m; ++i) { int u, v; scanf("%d%d", &u, &v); ans = (ans + LL(i) * len[u ^ v]) % mod; } cout << ans << endl; } return0; }