//#pragma comment(linker,"/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include #define ll long long #define db double #define PB push_back #define lson k<<1 #define rson k<<1|1 using namespace std; const int N = 50005; int w[N], cnt[N]; ll gcd(ll a, ll b) { if(a > b) swap(a, b); while(a) { ll t = a; a = b % a; b = t; } return b; } int main() { #ifdef PKWV // freopen("in.in","r",stdin); #endif // PKWV int T; scanf("%d", &T); while(T--) { int n, m; scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) scanf("%d", &w[i]), cnt[i] = 0; for(int i = 0; i < m; i++) { int l, r; scanf("%d%d", &l, &r); cnt[l]++, cnt[r + 1]--; } int num(0); ll tol(0LL); for(int i = 1; i <= n; i++) { num += cnt[i]; if(num >= 3) { tol += (ll)w[i] * (ll)num * (ll)(num - 1) * (ll)(num - 2) / 6LL; } } ll fm = 1LL; if(m >= 3) fm *= (ll)m * (ll)(m - 1) * (ll)(m - 2) / 6LL; ll g = gcd(tol, fm); tol /= g, fm /= g; if(fm == 1) printf("%I64d\n", tol); else printf("%I64d/%I64d\n", tol, fm); } return 0; }