#include <bits/stdc++.h>
#pragma GCC optimize("Ofast","unroll-loops")
#define ll long long
#define ft first
#define sec second
#define pb push_back
#define pi pair<ll,ll>
using namespace std;
int n;
vector<pi> G[200005];
ll dp[200005][60][2],ans;
const int mod=1e9+7;
void dfs(int now,int fa)
{
	for(int i=0; i<60; i++) dp[now][i][0]=1;
	for(pi v:G[now]) if(v.ft!=fa)
	{
		dfs(v.ft,now);
		for(int i=0; i<60; i++)
		{
			int k=((v.sec&(1LL<<i))!=0);
			dp[now][i][0]+=dp[v.ft][i][k];
			dp[now][i][1]+=dp[v.ft][i][1^k];
		}
	}
}
void sol(int now,int fa)
{
	ll cnt[60][2]={0};
	for(pi v:G[now]) if(v.ft!=fa)
	{
		sol(v.ft,now);
		for(int i=0; i<60; i++)
		{
			int k=((v.sec&(1LL<<i))!=0);
			ll add=(1LL<<i)%mod;
			ans=(ans+dp[v.ft][i][1^k]*add%mod)%mod;
			ans=(ans+add*cnt[i][0]%mod*dp[v.ft][i][1^k]%mod)%mod;
			ans=(ans+add*cnt[i][1]%mod*dp[v.ft][i][k]%mod)%mod;
			cnt[i][0]+=dp[v.ft][i][k];
			cnt[i][1]+=dp[v.ft][i][1^k];
		}
	}
	//if(now==3) cout << ans <<'\n'; 
	
}
int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(ll i=1,a,b,c; i<n; i++)
	{
		cin >> a >> b >> c;
		G[a].pb({b,c});
		G[b].pb({a,c});
	}
	dfs(1,1);
	sol(1,1);
	cout << ans;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;

#define nl '\n'


//----------------------------------- DEBUG -----------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
// debug & operator << (debug & dd, P p) { dd << "(" << p.x << ", " << p.y << ")"; return dd; }

//----------------------------------- END DEBUG --------------------------------

/*

(2, 3)
(4, 6)

2 < x < 3

x = 2.5 = 5

[3, 2]

*/

void run_cases() {
    int N;
    cin >> N;
    vector<vector<int64_t>> ranges(N);
    for(int i = 0; i < N; i++) {
        int64_t t, l, r;
        cin >> t >> l >> r;
        l *= 100;
        r *= 100;
        switch(t) {
            case 2:
                r--;
                break;
            case 3:
                l++;
                break;
            case 4:
                l++, r--;
                break;
        }
        ranges[i] = {l, r};
    }

    int ans = 0;

    auto intersect = [&](vector<int64_t> &a, vector<int64_t> &b) -> bool {
        vector<int64_t> common = {max(a[0], b[0]), min(a[1], b[1])};
        return common[0] <= common[1];
    };

    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            ans += intersect(ranges[i], ranges[j]);
        }
    }

    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr);

    int tests = 1;
    // cin >> tests;

    for(int test = 1;test <= tests;test++) {
        run_cases();
    }
}