#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pb push_back #define mp make_pair #define INF ll(1e18) #define mod 998244353 #define mod2 1000000007 #define eps 1e-9 #define abs(x) ((x)>=0?(x):-(x)) #define y1 solai #define fi first #define se second typedef long long ll; typedef long double ld; typedef pair pll; typedef pair pdd; const ll N=200100; ll n,a,b,c,p[30][N],r[30][N],ans; ll fin(ll a, ll t) { if(p[t][a]==a) return a; return p[t][a]=fin(p[t][a],t); } void uni(ll a, ll b, ll t) { a=fin(a,t),b=fin(b,t); if(a==b) return; if(r[t][a]>r[t][b]) r[t][a]+=r[t][b],p[t][b]=a; else r[t][b]+=r[t][a],p[t][a]=b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n; for(ll i=1;i<=n;i++) for(ll j=0;j<30;j++) p[j][i]=i,r[j][i]=1; for(ll i=1;i>a>>b>>c; for(ll j=0;j<30;j++) if((c>>j)&1) uni(a,b,j); } for(ll i=1;i<=n;i++) for(ll j=0;j<30;j++) if(fin(i,j)==i) ans+=r[j][i]*(r[j][i]-1)/2%mod2*(1<