#include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef pair pii; template inline void chkmin(T &x, U y) { if(y < x) x = y; } template inline void chkmax(T &x, U y) { if(x < y) x = y; } int n, m; #define MX 512345 int w[MX]; int val[MX]; LL C(int s) { return 1LL * s * (s - 1) * (s - 2) / 6; } int main() { int Tcase; for (scanf("%d", &Tcase); Tcase--;) { scanf("%d%d", &n, &m); LL tmp = C(m); memset(val, 0, sizeof val); for (int i = 1; i <= n; i++) scanf("%d", w + i); int x = m; while (m--) { int l, r; scanf("%d%d", &l, &r); val[l]++; val[r + 1]--; } int s = 0; int i; LL cnt(0); for (i = 1; i <= n; i++) { s += val[i]; val[i] = s; cnt += 1LL * w[i] * C(s); } if (tmp == 0) puts("0"); else { LL g = __gcd(cnt, tmp); cnt /= g, tmp /= g; if (tmp != 1) printf("%I64d/%I64d\n", cnt, tmp); else printf("%I64d\n", cnt); } } return 0; }