ll n = read(), m = read(), k = read(); ll p = C2(n), ans = C2(k) * m * qpow(p, k - 2), sum = 0; while (m--) { read(), read(); sum += read(); } ans += k * sum * qpow(p, k - 1); print(ans * qpow(qpow(p, k), MOD - 2));
#include<cstdio> typedeflonglong ll; constint MOD = 1e9 + 7;
inline ll read(){ char st; ll x = 0; int fu = 1; st = getchar(); while (st > 57 || st < 48) { if (st == 45) fu = -1; st = getchar(); }while (st <= 57 && st >= 48) { x = (x << 3) + (x << 1) + st - 48; st = getchar(); }return x * fu; } inline ll C2(ll x){ return x * (x - 1) / 2; } ll qpow(ll a, ll n){ if (n < 0) return0; ll ans = 1; while (n) { if (n & 1) ans = ans * a % MOD; a = a * a % MOD; n >>= 1; } return ans; }
voideachT(){ ll n = read(), m = read(), k = read(); ll p = C2(n) % MOD, ans = C2(k) % MOD * m % MOD * qpow(p, k - 2) % MOD, sum = 0; while (m--) read(), read(), sum = (sum + read()) % MOD; ans = (ans + k * sum % MOD * qpow(p, k - 1) % MOD) % MOD; printf("%lld\n", ans * qpow(qpow(p, k) % MOD, MOD - 2) % MOD); }
intmain(){ int T = read(); while (T--) eachT(); return0; }