#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef double DB; typedef pair PII; typedef vector VI; #define X first #define Y second #define pb push_back template inline void chkmin(T &x, T y) { if (y < x) x = y; } template inline void chkmax(T &x, T y) { if (x < y) x = y; } const int MN = 50005; int n, val[MN], m; int l[MN], r[MN], w[MN]; VI V[MN]; inline void add(int x) { for (; x <= n; x += x & -x) val[x]++; } inline int get(int x, int y) { int rlt = 0; x--; for (; x; x -= x & -x) rlt -= val[x]; for (; y; y -= y & -y) rlt += val[y]; return rlt; } int main() { // freopen("in.txt", "r", stdin); // freopen("out.txt", "w", stdout); int i, j, k, tn; for (scanf("%d", &tn); tn--; ) { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) V[i].clear(); for (i = 1; i <= n; i++) scanf("%d", w + i); for (i = 0; i < m; i++) { scanf("%d%d", l + i, r + i); V[l[i]].pb(r[i]); } if (m <= 2) { printf("0\n"); continue; } memset(val, 0, sizeof val); LL ans = 0; for (i = 1; i <= n; i++) { for (j = V[i].size() - 1; j >= 0; j--) { add(V[i][j]); } int t = get(i, n); if (t >= 3) { ans += 1LL * w[i] * t * (t - 1) * (t - 2) / 6; } } LL b = 1LL * m * (m - 1) * (m - 2) / 6; LL g = __gcd(ans, b); if (b == g) { printf("%lld\n", ans / g); } else { printf("%lld/%lld\n", ans / g, b / g); } } return 0; }