#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define all(x) (x).begin(), (x).end() #define bit(x) (1 << (x)) #define cnt1(x) (__builtin_popcount(x)) #define LET(it,v) __typeof(v) it(v) #define mset0(x) memset((x), 0, sizeof((x))) #define mset1(x) memset((x), -1, sizeof((x))) #define pb push_back #define PQ priority_queue #define REP(it,v) for(LET(it,v.begin());it!=v.end();it++) #define sqr(x) ((x) * (x)) #define sz(x) ((int)(x.size())) #define X first #define Y second using namespace std; typedef long long LL; typedef pair pii; typedef pair pll; typedef vector vi; typedef vector vpii; template inline void chkmin(T &a, T b) { if (b < a) a = b; } template inline void chkmax(T &a, T b) { if (a < b) a = b; } const int MX = 100005; int cnt[MX], w[MX]; LL C3(LL n) { return n * (n - 1) * (n - 2) / 6; } int main() { int T, n, m; int i; for (scanf("%d", &T); T--; ) { scanf("%d%d", &n, &m); for (i = 1; i <= n; i++) scanf("%d", w + i); for (i = 0; i <= n + 1; i++) cnt[i] = 0; int l, r; for (i = 1; i <= m; i++) { scanf("%d%d", &l, &r); cnt[l]++, cnt[r + 1]--; } if (m < 3) { puts("0"); continue; } LL ans = 0; for (i = 1; i <= n; i++) { cnt[i] += cnt[i - 1]; ans += w[i] * C3(cnt[i]); } LL tot = C3(m); LL tp = __gcd(tot, ans); ans /= tp, tot /= tp; if (tot == 1) printf("%lld\n", ans); else printf("%lld/%lld\n", ans, tot); } return 0; }