///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define endl '\n'
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << " " << H; debug_out(T...); }
#define debug(...) cerr << "{" << #__VA_ARGS__ << "}:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
const int MAXN = 1e5 + 10 , MOD = 1e9 + 7;
int n , k , v , x , ans , prnt , par[MAXN] , dep[MAXN];
int Find(int u)
{
	if(par[u] == -1)
		return u;
	int p = Find(par[u]);
	dep[u] = dep[par[u]] + dep[u];
	while(dep[u] < 0)
		dep[u] += MOD;
	dep[u] %= MOD , par[u] = p;
	return p;
}
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i <= n ; i ++)
		par[i] = -1 , dep[i] = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> k;
		for(int j = 0 ; j < k ; j ++)
		{
			cin >> v >> x , v -- , prnt = Find(v) , par[prnt] = i , dep[prnt] = dep[v] + x;
			while(dep[prnt] < 0)
				dep[prnt] += MOD;
			dep[prnt] %= MOD , ans += dep[prnt] , ans %= MOD;
		}
	}
	/*if(n == 100 * 1000)
		for(int i = 0 ; i < n - 1 ; i ++)
			cout << dep[i] << " ";
	cout << '\n';*/
	return cout << (ans + MOD) % MOD << '\n' , 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10 , MOD = 1e9 + 7;
int n , k , v , x , ans , prnt , par[MAXN] , dep[MAXN];
int Find(int u)
{
	if(u == par[u])
		return u;
	dep[u] = (dep[par[u]] + dep[u]) % MOD;
	return par[u] = Find(par[u]);
}
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i <= n ; i ++)
		par[i] = i , dep[i] = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> k;
		for(int j = 0 ; j < k ; j ++)
		{
			cin >> v >> x , v -- , prnt = Find(v) , ans = (ans + dep[v] + x + MOD) % MOD , par[prnt] = i , dep[prnt] = (dep[v] + x) % MOD;
			while(dep[v] < 0)
				dep[v] += MOD;
			dep[v] %= MOD;
		}
	}
	/*if(n == 100 * 1000)
		for(int i = 0 ; i < n - 1 ; i ++)
			cout << dep[i] << " ";
	cout << '\n';*/
	return cout << (ans + MOD) % MOD << '\n' , 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10 , MOD = 1e9 + 7;
int n , k , v , x , ans , prnt , par[MAXN] , dep[MAXN];
int Find(int u)
{
	if(u == par[u])
		return u;
	dep[u] = (dep[par[u]] + dep[u]) % MOD;
	return par[u] = Find(par[u]);
}
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i <= n ; i ++)
		par[i] = i , dep[i] = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> k;
		for(int j = 0 ; j < k ; j ++)
			cin >> v >> x , v -- , prnt = Find(v) , ans = (ans + dep[v] + x) % MOD , par[prnt] = i , dep[prnt] = (dep[v] + x) % MOD;
	}
	/*for(int i = 0 ; i < n ; i ++)
		cout << dep[i] << " ";
	cout << '\n';*/
	return cout << (ans + MOD) % MOD << '\n' , 0;
}


///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back
#define pb push_back
#define mp make_pair
#define int long long
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
typedef map<int , int> mii;
typedef pair<int , int> pii;
typedef map<string , int> msi;
typedef pair<int , string> pis;
typedef pair<int , pair<int , int> > piii;
const int MAXN = 1e5 + 10 , MOD = 1e9 + 7;
int n , k , v , x , ans , prnt , par[MAXN] , dep[MAXN];
int Find(int u)
{
	if(u == par[u])
		return u;
	dep[u] = (dep[par[u]] + dep[u]) % MOD;
	return par[u] = Find(par[u]);
}
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i <= n ; i ++)
		par[i] = i , dep[i] = 0;
	for(int i = 0 ; i < n ; i ++)
	{
		cin >> k;
		for(int j = 0 ; j < k ; j ++)
			cin >> v >> x , v -- , prnt = Find(v) , ans = (ans + dep[v] + x + MOD) % MOD , par[prnt] = i , dep[prnt] = (dep[v] + x) % MOD;
	}
	if(n == 100 * 1000)
		for(int i = 0 ; i < n - 1 ; i ++)
			cout << dep[i] << " ";
	cout << '\n';
	return cout << (ans + MOD) % MOD << '\n' , 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
typedef long long ll;
#define MAX 100035
using namespace std;
#define INF 2147483647
#define inf 1<<30
#define MOD 1000000007
#define EPS 1e-20
#define G 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool debug = false;
int n,m, k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

int f[MAX];
ll dis[MAX],ans;
int ff(int x) {
    if (x==f[x]) return x;
    int fa = f[x];
    int gfa = ff(f[x]);
    f[x]=gfa;
    dis[x] = (dis[x] + dis[fa])%MOD;
    return gfa;
}
int main(){
    scanf("%d", &n);
    REP(i,n) f[i+1]=i+1;
    for(int i=1;i<=n;i++) {
        scanf("%d", &k);
        for(int v,x,j=0;j<k;j++) {
            scanf("%d%d", &v, &x);
            int fa = ff(v);

            f[fa]=i;
            dis[fa] = (dis[v] + x)%MOD;
            ans = (ans + dis[fa]) % MOD;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
#include <cctype>
typedef long long ll;
#define MAX 100035
using namespace std;
#define INF 2147483647
#define inf 1<<30
#define MOD 1000000007
#define EPS 1e-20
#define G 9.8
#define PI acos(-1)
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
bool debug = false;
int n,m, k;
int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};

int f[MAX];
ll dis[MAX],ans;
int ff(int x) {
    if (x==f[x]) return x;
    int fa = f[x];
    int gfa = ff(f[x]);
    f[x]=gfa;
    dis[x] = (dis[x] + dis[fa])%MOD;
    return gfa;
}
int main(){
    scanf("%d", &n);
    REP(i,n) f[i+1]=i+1;
    for(int i=1;i<=n;i++) {
        scanf("%d", &k);
        for(int v,x,j=0;j<k;j++) {
            scanf("%d%d", &v, &x);
            int fa = ff(v);
            f[fa]=i;
            dis[fa] = (dis[v] + x)%MOD;
            ans = (ans + dis[fa])%MOD ;
        }
    }
    printf("%lld\n", (ans+MOD)%MOD);
    return 0;
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 100010
using namespace std;
vector<pair<pair<int, int>, int> > quer[N];
int par[N], sz[N], in[N], val[N], ct = 0, tree[4 * N], lazy[4 * N], visited[N];
vector<int> graph[N];
pair<int, int> rng[N];
int mult(int a, int b){
	return 1LL * a * b % MOD;
}
int add(int a, int b){
	return (a + b) % MOD;
}
int root(int a){
	while(par[a] != a){
		a = par[a];
		par[a] = par[par[a]];
	}
	return a;
}
void unionit(int a, int b){
	int x = root(a);
	int y = root(b);
	if(sz[x] < sz[y]){
		par[x] = y;
		sz[y] += sz[x];
	}
	else {
		par[y] = x;
		sz[x] += sz[y];
	}
}
void dfs(int s, int par){
	visited[s] = 1;
	//conv[ct] = s;
	in[s] = ct++;
	for(auto to: graph[s]){
		if(to != par){
			dfs(to, s);
		}
	}
	rng[s] = mp(in[s], ct - 1);
}
void push(int low, int high, int node){
	if(lazy[node]){
		tree[node] = add(tree[node], mult(high - low + 1, lazy[node]));
		if(low != high){
			lazy[2 * node] = add(lazy[2 * node], lazy[node]);
			lazy[2 * node + 1] = add(lazy[2 * node + 1], lazy[node]);
		}
		lazy[node] = 0;
	}
}
void update(int low, int high, int begin, int end, int val, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return;
	if(low >= begin & high <= end){
		lazy[node] = val;
		push(low, high, node);
		return;
	}
	int mid = (low + high) / 2;
	update(low, mid, begin, end, val, 2 * node);
	update(mid + 1, high, begin, end, val, 2 * node + 1);
	tree[node] = add(tree[2 * node],  tree[2 * node + 1]);
}
int query(int low, int high, int begin, int end, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return 0;
	if(low >= begin && high <= end)
		return tree[node];
	int mid = (low + high) / 2;
	return add(query(low, mid, begin, end, 2 * node), query(mid + 1, high, begin, end, 2 * node + 1));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		par[i] = i, sz[i] = 1;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		for(int j = 0; j < k; j++){
			int v, x;
			cin >> v >> x;
			x = (x + MOD) % MOD;
			v--;
			int y = val[root(v)];
			unionit(v, i);
			graph[y].pb(i);
			graph[i].pb(y);
			//cerr << y + 1 << " " << i + 1 << '\n';
			quer[i].pb(mp(mp(v, x), y));
		}
		val[root(i)] = i;
	}
	for(int i = n - 1; i >= 0; i--){
		if(!visited[i]){
			dfs(i, -1);
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < quer[i].size(); j++){
			int y = query(0, n - 1, in[quer[i][j].first.first], in[quer[i][j].first.first], 1);
			ans = add(ans, add(y, quer[i][j].first.second));
			//cerr << y << " " << y + quer[i][j].first.second << " " << rng[quer[i][j].second].first << " " << rng[quer[i][j].second].second <<'\n';
			update(0, n - 1, rng[quer[i][j].second].first, rng[quer[i][j].second].second, add(y, quer[i][j].first.second), 1);
		}
	}
	cout << ans << '\n';
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 100010
using namespace std;
vector<pair<pair<int, int>, int> > quer[N];
int par[N], sz[N], in[N], val[N], ct = 0, tree[4 * N], lazy[4 * N], visited[N];
vector<int> graph[N];
pair<int, int> rng[N];
int mult(int a, int b){
	return 1LL * a * b % MOD;
}
int add(int a, int b){
	return (a + b) % MOD;
}
int root(int a){
	while(par[a] != a){
		a = par[a];
		par[a] = par[par[a]];
	}
	return a;
}
void unionit(int a, int b){
	int x = root(a);
	int y = root(b);
	if(sz[x] < sz[y]){
		par[x] = y;
		sz[y] += sz[x];
	}
	else {
		par[y] = x;
		sz[x] += sz[y];
	}
}
void dfs(int s, int par){
	visited[s] = 1;
	//conv[ct] = s;
	in[s] = ct++;
	for(auto to: graph[s]){
		if(to != par){
			dfs(to, s);
		}
	}
	rng[s] = mp(in[s], ct - 1);
}
void push(int low, int high, int node){
	if(lazy[node]){
		tree[node] = add(tree[node], mult(high - low + 1, lazy[node]));
		if(low != high){
			lazy[2 * node] = add(lazy[2 * node], lazy[node]);
			lazy[2 * node + 1] = add(lazy[2 * node + 1], lazy[node]);
		}
		lazy[node] = 0;
	}
}
void update(int low, int high, int begin, int end, int val, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return;
	if(low >= begin & high <= end){
		lazy[node] = val;
		push(low, high, node);
		return;
	}
	int mid = (low + high) / 2;
	update(low, mid, begin, end, val, 2 * node);
	update(mid + 1, high, begin, end, val, 2 * node + 1);
	tree[node] = add(tree[2 * node],  tree[2 * node + 1]);
}
int query(int low, int high, int begin, int end, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return 0;
	if(low >= begin && high <= end)
		return tree[node];
	int mid = (low + high) / 2;
	return add(query(low, mid, begin, end, 2 * node), query(mid + 1, high, begin, end, 2 * node + 1));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		par[i] = i, sz[i] = 1;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		for(int j = 0; j < k; j++){
			int v, x;
			cin >> v >> x;
			x = (x + MOD) % MOD;
			v--;
			int y = val[root(v)];
			unionit(v, i);
			graph[y].pb(i);
			graph[i].pb(y);
			//cerr << y + 1 << " " << i + 1 << '\n';
			quer[i].pb(mp(mp(v, x), y));
		}
		val[root(i)] = i;
	}
	for(int i = n - 1; i >= 0; i--){
		if(!visited[i]){
			dfs(i, -1);
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < quer[i].size(); j++){
			int y = query(0, n - 1, in[quer[i][j].first.first], in[quer[i][j].first.first], 1);
			ans = add(ans, y + quer[i][j].first.second);
			//cerr << y << " " << y + quer[i][j].first.second << " " << rng[quer[i][j].second].first << " " << rng[quer[i][j].second].second <<'\n';
			update(0, n - 1, rng[quer[i][j].second].first, rng[quer[i][j].second].second, y + quer[i][j].first.second, 1);
		}
	}
	cout << ans << '\n';
}


#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back
#define N 100010
using namespace std;
vector<pair<pair<int, int>, int> > quer[N];
int par[N], sz[N], in[N], val[N], ct = 0, tree[4 * N], lazy[4 * N], visited[N];
vector<int> graph[N];
pair<int, int> rng[N];
int mult(int a, int b){
	return 1LL * a * b % MOD;
}
int add(int a, int b){
	return (a + b) % MOD;
}
int root(int a){
	while(par[a] != a){
		a = par[a];
		par[a] = par[par[a]];
	}
	return a;
}
void unionit(int a, int b){
	int x = root(a);
	int y = root(b);
	if(sz[x] < sz[y]){
		par[x] = y;
		sz[y] += sz[x];
	}
	else {
		par[y] = x;
		sz[x] += sz[y];
	}
}
void dfs(int s, int par){
	visited[s] = 1;
	//conv[ct] = s;
	in[s] = ct++;
	for(auto to: graph[s]){
		if(to != par){
			dfs(to, s);
		}
	}
	rng[s] = mp(in[s], ct - 1);
}
void push(int low, int high, int node){
	if(lazy[node]){
		tree[node] = add(tree[node], mult(high - low + 1, lazy[node]));
		if(low != high){
			lazy[2 * node] = add(lazy[2 * node], lazy[node]);
			lazy[2 * node + 1] = add(lazy[2 * node + 1], lazy[node]);
		}
		lazy[node] = 0;
	}
}
void update(int low, int high, int begin, int end, int val, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return;
	if(low >= begin & high <= end){
		lazy[node] = val;
		push(low, high, node);
		return;
	}
	int mid = (low + high) / 2;
	update(low, mid, begin, end, val, 2 * node);
	update(mid + 1, high, begin, end, val, 2 * node + 1);
	tree[node] = add(tree[2 * node],  tree[2 * node + 1]);
}
int query(int low, int high, int begin, int end, int node){
	push(low, high, node);
	if(low > end || high < begin)
		return 0;
	if(low >= begin && high <= end)
		return tree[node];
	int mid = (low + high) / 2;
	return add(query(low, mid, begin, end, 2 * node), query(mid + 1, high, begin, end, 2 * node + 1));
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	for(int i = 0; i < n; i++)
		par[i] = i, sz[i] = 1;
	for(int i = 0; i < n; i++){
		int k;
		cin >> k;
		for(int j = 0; j < k; j++){
			int v, x;
			cin >> v >> x;
			v--;
			int y = val[root(v)];
			unionit(v, i);
			graph[y].pb(i);
			graph[i].pb(y);
			//cerr << y + 1 << " " << i + 1 << '\n';
			quer[i].pb(mp(mp(v, x), y));
		}
		val[root(i)] = i;
	}
	for(int i = n - 1; i >= 0; i--){
		if(!visited[i]){
			dfs(i, -1);
		}
	}
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = 0; j < quer[i].size(); j++){
			int y = query(0, n - 1, in[quer[i][j].first.first], in[quer[i][j].first.first], 1);
			ans = add(ans, y + quer[i][j].first.second);
			//cerr << y << " " << y + quer[i][j].first.second << " " << rng[quer[i][j].second].first << " " << rng[quer[i][j].second].second <<'\n';
			update(0, n - 1, rng[quer[i][j].second].first, rng[quer[i][j].second].second, y + quer[i][j].first.second, 1);
		}
	}
	cout << ans << '\n';
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;
#define f first
#define s second
#define Mp make_pair
#define pb push_back
#define ppb pop_back
#define Lb lower_bound
#define Ub upper_bound
#define all(x) x.begin(), x.end()
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll Maxn = 2e5+5, N = 4e5+5, Mod = 1e9+7, Inf = 1e18, Log = 22;
int n, k, par[Maxn];
ll ans = 0, depth[Maxn];
pair <int, int> Find(int v){
   if (par[v] == v){
        return {v, v};
    }
    pair <int, int> p = Find(par[v]);
    par[v] = p.f;
    depth[v] = (depth[v]+depth[p.s]+Mod)%Mod;
    return {p.f, v};
}
void Union(int i, int v, ll x){
    pair <int, int> haha = Find(v);
    int vp = haha.f;
    par[vp] = i;
    depth[vp] = (depth[v]+x+Mod)%Mod;
    ans = (ans+depth[vp]+Mod)%Mod;
    return;
}
int main(){
    fast_io
    cin >> n;
    for (int i = 1; i <= n; i++){
        par[i] = i;
    }
    for (int i = 1; i <= n; i++){
        int k;
        cin >> k;
        for (int j = 0; j < k; j++){
            int v, x;
            cin >> v >> x;
            Union(i, v, x);
        }
    }
    cout << ans << '\n';
    return 0;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int64_t, int64_t>> p;
void build() {
	int64_t n = p.size();
	for (int64_t i = 0; i < n; ++i) {
		p[i] = { i,0 };
	}
}
const int64_t inf = 1e9 + 7;
pair<int64_t, int64_t> getp(int64_t v) {
	if (p[v].first == v) return { v,0 };
	else {
		pair<int64_t, int64_t> q = getp(p[v].first);
		p[v].first = q.first;
		p[v].second += q.second+inf;
		p[v].second %= inf;
		return p[v];
	}
}
void update(int64_t a, int64_t b, int64_t w) {
	pair<int64_t, int64_t> a1 = getp(a);
	pair<int64_t, int64_t> b1 = getp(b);
	if (a1.first != b1.first) {
		p[b1.first] = { a1.first,w };
	}
}

int main() {
	int64_t n;
	cin >> n;
	p.resize(n);
	build();
	int64_t ans = 0;
	for (int64_t i = 0; i < n; ++i) {
		int64_t k;
		cin >> k;
		vector<pair<int64_t, int64_t>> ask;
		for (int64_t j = 0; j < k; ++j) {
			int64_t v, f;
			cin >> v >> f;
			--v;
			ask.push_back({ v,(f + getp(v).second) % inf });
		}
		for (auto elem : ask) {
			ans += elem.second + inf;
			ans %= inf;
			update(i, elem.first, elem.second);
		}
	}
	cout << ans;
}


#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<pair<int64_t, int64_t>> p;
void build() {
	int64_t n = p.size();
	for (int64_t i = 0; i < n; ++i) {
		p[i] = { i,0 };
	}
}
const int64_t inf = 1e9 + 7;
pair<int64_t, int64_t> getp(int64_t v) {
	if (p[v].first == v) return { v,0 };
	else {
		pair<int64_t, int64_t> q = getp(p[v].first);
		p[v].first = q.first;
		p[v].second += q.second;
		p[v].second %= inf;
		return p[v];
	}
}
void update(int64_t a, int64_t b, int64_t w) {
	pair<int64_t, int64_t> a1 = getp(a);
	pair<int64_t, int64_t> b1 = getp(b);
	if (a1.first != b1.first) {
		p[b1.first] = { a1.first,w };
	}
}

int main() {
	int64_t n;
	cin >> n;
	p.resize(n);
	build();
	int64_t ans = 0;
	for (int64_t i = 0; i < n; ++i) {
		int64_t k;
		cin >> k;
		vector<pair<int64_t, int64_t>> ask;
		for (int64_t j = 0; j < k; ++j) {
			int64_t v, f;
			cin >> v >> f;
			--v;
			ask.push_back({ v,(f + getp(v).second) % inf });
		}
		for (auto elem : ask) {
			ans += elem.second;
			ans %= inf;
			update(i, elem.first, elem.second);
		}
	}
	cout << ans;
}


///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
const int mx = 1e5 + 10, M = 1e9 + 7;
int par[mx], w[mx];
int findpar(int v){
	return(par[v] == v ? v : par[v] = findpar(par[v]));
}
int findwei(int v){
	return(par[v] == v ? 0 : w[v] = w[v] + findwei(par[v]));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k, e, v, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> k;
		par[i] = i;
		for(int j = 0; j < k; j++){
			cin >> v >> e;
			int wei = findwei(v);
			v = findpar(v);
			w[v] = (wei + e) % M;
			par[v] = i;
			ans = (ans + w[v] + M) % M;
		}
	}
//	if(ans < 0)
//		ans += M;
	cout << ans << endl;
	return 0;
}


///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
const int mx = 1e5 + 10, M = 1e9 + 7;
int par[mx], w[mx];
int findpar(int v){
	return(par[v] == v ? v : par[v] = findpar(par[v]));
}
int findwei(int v){
	return(par[v] == v ? 0 : w[v] = w[v] + findwei(par[v]));
}
int32_t main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k, e, v, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> k;
		par[i] = i;
		for(int j = 0; j < k; j++){
			cin >> v >> e;
			int wei = findwei(v);
			v = findpar(v);
			w[v] = (wei + e) % M;
			par[v] = i;
			ans = (ans + w[v]) % M;
		}
	}
	cout << ans << endl;
	return 0;
}


///A drunk man will find his way home, but a drunk bird may get lost forever...
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
//template <typename T>
//using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef tree<double, null_type, less<double>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//#define int long long
typedef long long ll;
typedef double dd;
typedef long double ldd;
typedef pair <int, int> pii;
typedef pair <pii , int> ppii;
#define pb push_back
#define pf push_front
#define ppb pop_back()
#define ppf pop_front()
#define f first
#define s second
#define sz(x) (int)x.size()
#define smin(x , y) x = min(x , y)
#define smax(x , y) x = max(x , y)
#define mp make_pair
#define all(x) x.begin() , x.end()
#define debug(x) cerr<< #x << " = " << x << endl
#define ddebug(x, y) cerr<< #x << " = " << x  << ", " << #y << " = " << y << endl
#define uop(x, y) pii(min(x, y), max(x, y))
#define mem(a, b) memset(a, b, sizeof a)
const int mx = 1e5 + 10, M = 1e9 + 7;
int par[mx], w[mx];
int findpar(int v){
	return(!par[v] ? v : par[v] = findpar(par[v]));
}
int findwei(int v){
	return(!par[v] ? 0 : w[v] = w[v] + findwei(par[v]));
}
int main(){
    ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n, k, e, v, ans = 0;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> k;
		for(int j = 0; j < k; j++){
			cin >> v >> e;
			int wei = findwei(v);
			v = findpar(v);
			w[v] = (wei + e) % M;
			par[v] = i;
			ans = (ans + w[v]) % M;
		}
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
bool isPrime(long long int x) {
	if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
	for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;
}

#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"
#define debug(M) for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cout<<(M)[i][j]<< " ";}cout<<endl;}
//#define LONG_LONG_MAX  9223372036854775807
//#define LONG_LONG_MIN   -9223372036854775807
//#define max3(a, b, c) max(a, max(b, c))
//#define min3(a, b, c) min(a, min(b, c))
//#define PI 3.14159265
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}

const int INF = int(1e17 + 7);

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}
int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

const int modulo = 1e9 + 7;
const int MAXN = 1e5 + 5;

vector<pair<int, int>> gr[MAXN];

int const maxn = 2e5 + 5;
int par[maxn];
int rnk[maxn];
vector<int> del;
vector<int> add;
int used[maxn];

int maxS = 51;
vector<int> cnt(maxn,0);
vector<string> S;

int getpar(int x) {
	//return par[x] == x ? x : par[x] = getpar(par[x]);
	if(par[x] == x)
	 return x;
	int res = getpar(par[x]);
	cnt[x] = (cnt[x] + cnt[par[x]]) % modulo;
	return par[x] = res;
}

int ans1 = 0, ans2 = 0;

void uni(int x, int y) {
	x = getpar(x);
	y = getpar(y);
	if (x != y) {
		par[y] = x;
	}
}

bool compa(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

int32_t main()
{
	iota(begin(par), end(par), 0);
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<pair<int,int>>> e(n);
	for (int i = 1; i <= n; ++i) {
		int k;
		cin >> k;
		forj(k) {
			int v, w;
			cin >> v >> w;
			v = abs(v); w = abs(w);
			int pv = getpar(v);
			int cur = cnt[v];
			cur = (cur + w) % modulo;
			ans = (ans + cur) % modulo;
			cnt[pv] = (cnt[pv] + cur) % modulo;
			par[pv] = i;
		}

	}
	cout << ans;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
bool isPrime(long long int x) {
	if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
	for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;
}

#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"
#define debug(M) for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cout<<(M)[i][j]<< " ";}cout<<endl;}
//#define LONG_LONG_MAX  9223372036854775807
//#define LONG_LONG_MIN   -9223372036854775807
//#define max3(a, b, c) max(a, max(b, c))
//#define min3(a, b, c) min(a, min(b, c))
//#define PI 3.14159265
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}

const int INF = int(1e17 + 7);

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}
int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

const int modulo = 1e9 + 7;
const int MAXN = 1e5 + 5;

vector<pair<int, int>> gr[MAXN];

int const maxn = 2e5 + 5;
int par[maxn];
int rnk[maxn];
vector<int> del;
vector<int> add;
int used[maxn];

int maxS = 51;
vector<int> cnt(maxn,0);
vector<string> S;

int getpar(int x) {
	//return par[x] == x ? x : par[x] = getpar(par[x]);
	if(par[x] == x)
	 return x;
	int res = getpar(par[x]);
	cnt[x] = (cnt[x] + cnt[par[x]]) % modulo;
	return par[x] = res;
}

int ans1 = 0, ans2 = 0;

void uni(int x, int y) {
	x = getpar(x);
	y = getpar(y);
	if (x != y) {
		par[y] = x;
	}
}

bool compa(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

int32_t main()
{
	iota(begin(par), end(par), 0);
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<pair<int,int>>> e(n);
	for (int i = 1; i <= n; ++i) {
		int k;
		cin >> k;
		forj(k) {
			int v, w;
			cin >> v >> w;
			while (w < 0)
				w += modulo;
			while (w >= modulo)
				w -= modulo;
			int pv = getpar(v);
			int cur = cnt[v];
			cur = (cur + w) % modulo;
			ans = (ans + cur) % modulo;
			cnt[pv] = (cnt[pv] + cur) % modulo;
			par[pv] = i;
		}

	}
	cout << ans;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
int add(int a, int b) {if((a += b) >= P) a -= P; return a;}
int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 1e5 + 7;
int d[N], f[N], n, k, x, w, xx, ans;

int get(int x) {
	if (x == f[x]) return x;
	int fa = f[x];
	f[x] = get(f[x]);
	d[x] = add(d[x], d[fa]);
	return f[x];
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n;
	rep(i, 1, n+1) {
		cin >> k;
		f[i] = i;
		rep(j, 0, k) {
			cin >> x >> w;
			xx = get(x);
			f[xx] = i;
			d[xx] = add(w, d[x]);
			ans = add(ans, d[xx]);
		}
	}
	cout << ans;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll<<(x))
#define endl "\n"
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int P = 1e9 + 7;
int add(int a, int b) {(a += b) %= P;if (a < 0) a += P; return a;}
int sub(int a, int b) {if((a -= b) < 0) a += P; return a;}
int mul(int a, int b) {return 1ll * a * b % P;}
int kpow(int a, int b) {int r=1;for(;b;b>>=1,a=mul(a,a)) {if(b&1)r=mul(r,a);}return r;}
//----

const int N = 1e5 + 7;
int d[N], f[N], n, k, x, w, xx, ans;

int get(int x) {
	if (x == f[x]) return x;
	int fa = f[x];
	f[x] = get(f[x]);
	d[x] = add(d[x], d[fa]);
	return f[x];
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	//cout << setiosflags(ios::fixed);
	//cout << setprecision(2);
	cin >> n;
	rep(i, 1, n+1) {
		cin >> k;
		f[i] = i;
		rep(j, 0, k) {
			cin >> x >> w;
			xx = get(x);
			f[xx] = i;
			d[xx] = add(w, d[x]);
			ans = add(ans, d[xx]);
		}
	}
	cout << ans;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
const ll mod = (ll) 1e9 + 7;
const int N = 100005;
ll p[N] , d[N];

int find(int x){
	if(p[x] == x) return x;
	find(p[x]);
	d[x] = (d[x] + d[p[x]])%mod;
	return p[x] = find(p[x]);
}

int n ;

int32_t main(){
	cin >> n;
	ll ans =0 ;
	rep(i,1,n+1) p[i] = i , d[i] = 0;
	rep(i,1,n+1){
		int k;
		cin >> k;
		rep(j,0,k){
			int v ;
			ll x;
			cin >> v >> x;
			int u = find(v);
			d[u] = (d[v] + x)%mod;
			ans = (ans + d[u])%mod;
			p[u] = i;
		}
	}
	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
const ll mod = (ll) 1e9 + 7;
const int N = 100005;
ll p[N] , d[N];

int find(int x){
	if(p[x] == x) return x;
	find(p[x]);
	d[x] = (d[x] + d[p[x]])%mod;
	return p[x] = find(p[x]);
}

int n ;

int32_t main(){
	cin >> n;
	ll ans =0 ;
	rep(i,1,n+1) p[i] = i , d[i] = 0;
	rep(i,1,n+1){
		int k;
		cin >> k;
		rep(j,0,k){
			int v ;
			ll x;
			cin >> v >> x;
			int u = find(v);
			d[u] = (d[v] + x)%mod;
			ans = (ans + d[u])%mod;
			p[u] = i;
		}
	}
	cout << (ans%mod+mod)%mod << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define per(i, a, b) for(int i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<pll> vpl;
typedef vector<int> vi;
ll modpow(ll b, ll e ,ll mod) {
	ll ans = 1;
	for (; e; b = b * b % mod, e /= 2)
		if (e & 1) ans = ans * b % mod;
	return ans;
}
const ll mod = (ll) 1e9 + 7;
const int N = 100005;
ll p[N] , d[N];

int find(int x){
	if(p[x] == x) return x;
	find(p[x]);
	d[x] = (d[x] + d[p[x]])%mod;
	return p[x] = find(p[x]);
}

int n ;

int32_t main(){
	cin >> n;
	ll ans =0 ;
	rep(i,1,n+1) p[i] = i , d[i] = 0;
	rep(i,1,n+1){
		int k;
		cin >> k;
		rep(j,0,k){
			int v , x;
			cin >> v >> x;
			int u = find(v);
			d[u] = (d[v] + x)%mod;
			ans = (ans + d[u])%mod;
			p[u] = i;
		}
	}
	cout << ans << endl;
}


//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long            ll;
typedef long double          ld;
typedef string               str;
typedef pair < ll , ll >     pll;

#define X               first
#define Y               second
#define pb              push_back
#define sep             ' '
#define endl            '\n'
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbl_io(x)       cout << fixed << setprecision(x);

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

ll par[N], dep[N];

ll getPar(ll v){
	if (par[v] == v)
		return v;
	ll p = getPar(par[v]);
	dep[v] = (dep[v] + dep[par[v]]) % mod;
	par[v] = par[par[p]];
	return p;
}

int main(){
    fast_io
    //dbl_io(10);
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i ++){
    	par[i] = i;
    	ll t;
    	cin >> t;
    	for (ll j = 0; j < t; j ++){
    		ll v, w;
    		cin >> v >> w;
    		ll p = getPar(v);
    		par[p] = i;
    		dep[p] = (dep[v] + w) % mod;
    		ans = (ans + dep[p]) % mod;
    	}
    }
    cout << ans;
    return 0;
}


//In The Name of Allah
#include <bits/stdc++.h>

using namespace std;

typedef long long            ll;
typedef long double          ld;
typedef string               str;
typedef pair < ll , ll >     pll;

#define X               first
#define Y               second
#define pb              push_back
#define sep             ' '
#define endl            '\n'
#define fast_io         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define dbl_io(x)       cout << fixed << setprecision(x);

const int N = 1e5 + 10;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

ll par[N], dep[N];

ll getPar(ll v){
	if (par[v] == v)
		return v;
	ll p = getPar(par[v]);
	dep[v] = (dep[v] + dep[par[v]]) % mod;
	par[v] = par[par[p]];
	return p;
}

int main(){
    fast_io
    //dbl_io(10);
    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i ++){
    	par[i] = i;
    	ll t;
    	cin >> t;
    	for (ll j = 0; j < t; j ++){
    		ll v, w;
    		cin >> v >> w;
    		ll p = getPar(v);
    		par[p] = i;
    		dep[p] = (dep[v] + w) % mod;
    		ans = (ans + dep[p]) % mod;
    	}
    }
    cout << (ans + mod) % mod;
    return 0;
}


// Problem : E. Building Forest
// Contest : Codeforces - Codeforces Round #123 (Div. 2)
// URL : https://codeforces.com/problemset/problem/195/E
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

/*
 A Submission by $%U%$
 at time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "cseq.inp"
#define FILE_OUT "cseq.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAXN 100000
#define mag 320
#define p1 first
#define p2 second.first
#define p3 second.second
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define piii pair<int,pii>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define bi BigInt
typedef long long ll;
//---------END-------//
int c[MAXN+5];
int sum[MAXN+5];

void init(int n){
    for(int i=1;i<=n;++i){
        c[i] = i;
    }
}

int root(int v){
    if(c[v] == v){
        return v;
    }
    else{
        int u = root(c[v]);
        sum[v] = (sum[c[v]] + sum[v]) % MOD;
        c[v] = u;
        return u;
    }
}

int main(){
	fio;
    int n, k, res = 0;
    cin>>n;
    init(n);
    for(int i=1;i<=n;++i){
        cin>>k;
        for(int j=0;j<k;++j){
            int v, x;
            cin>>v>>x;
            int u = root(v);
            c[u] = i;
            sum[u] = (sum[v] + x) % MOD;
            res = (res + sum[u]) % MOD;
        }
    }
    if(res < 0) res += MOD;
    cout << res << endl;
}


// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000, MD = 1000000007;

int pp[N], ww[N];

int find(int i) {
	int p = pp[i];
	if (p == -1)
		return i;
	pp[i] = find(p);
	ww[i] = (ww[i] + ww[p]) % MD;
	return pp[i];
}

int main() {
	int n; cin >> n;
	fill(pp, pp + n, -1);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		while (k--) {
			int j, x; cin >> j >> x, j--;
			int r = find(j);
			int w = (ww[j] + x) % MD;
			pp[r] = i;
			ww[r] = w;
			ans = (ans + w) % MD;
		}
	}
	if (ans < 0)
		ans += MD;
	cout << ans << '\n';
	return 0;
}


// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 100000, MD = 1000000007;

int pp[N], ww[N];

int find(int i) {
	int p = pp[i];
	if (p == -1)
		return i;
	pp[i] = find(p);
	ww[i] = (ww[i] + ww[p]) % MD;
	return pp[i];
}

int main() {
	int n; cin >> n;
	fill(pp, pp + n, -1);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		while (k--) {
			int j, x; cin >> j >> x, j--;
			int r = find(j);
			int w = (ww[j] + x) % MD;
			pp[r] = i;
			ww[r] = w;
			ans = (ans + w) % MD;
		}
	}
	cout << ans << '\n';
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

vector <pii> vec;
int num[maxn], par[maxn];

int root (int v) {
	return ((par[v] < 0) ? v : root(par[v]));
}

int sum (int v) {
	return (num[v] + ((par[v] < 0) ? 0 : sum(par[v]))) % mod;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(par, -1, sizeof par);
	int n, res = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		if (k == 0)
			continue;
		int mx, mxsz = 0, mxval;
		vec.clear();
		for (int t = 0; t < k; t++) {
			int v, x;
			cin >> v >> x;
			--v;
			vec.push_back(MP(root(v), (x + sum(v)) % mod));
			res = (res + vec.back().S) % mod;
			if (-par[vec.back().F] > mxsz)	{
				mxsz = -par[vec.back().F];
				mx = vec.back().F;
				mxval = vec.back().S;
			}
		}
		num[mx] = (num[mx] + mxval) % mod;
		par[mx] -= 1;
		num[i] -= num[mx];
		par[i] = mx;
		for (auto x : vec) {
			int u = x.F, val = x.S;
			if (u == mx)
				continue;
			par[mx] += par[u];
			par[u] = mx;
			num[u] = ((num[u] + val) % mod - num[mx]) % mod;
		}
	}
	cout << (res + mod) % mod << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

vector <pii> vec;
int num[maxn], par[maxn];

int root (int v) {
	return ((par[v] < 0) ? v : root(par[v]));
}

int sum (int v) {
	return (num[v] + ((par[v] < 0) ? 0 : sum(par[v]))) % mod;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(par, -1, sizeof par);
	int n, res = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		if (k == 0)
			continue;
		int mx, mxsz = 0, mxval;
		vec.clear();
		for (int t = 0; t < k; t++) {
			int v, x;
			cin >> v >> x;
			--v;
			vec.push_back(MP(root(v), (x + sum(v)) % mod));
			res = (res + vec.back().S) % mod;
			if (-par[vec.back().F] > mxsz)	{
				mxsz = -par[vec.back().F];
				mx = vec.back().F;
				mxval = vec.back().S;
			}
		}
		num[mx] = (num[mx] + mxval) % mod;
		par[mx] -= 1;
		num[i] -= mxval;
		par[i] = mx;
		for (auto x : vec) {
			int u = x.F, val = x.S;
			if (u == mx)
				continue;
			par[mx] += par[u];
			par[u] = mx;
			num[u] = ((num[u] + val) % mod - num[mx]) % mod;
		}
	}
	cout << (res + mod) % mod << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

vector <pii> vec;
int num[maxn], par[maxn];

int root (int v) {
	return ((par[v] < 0) ? v : root(par[v]));
}

int sum (int v) {
	return 1LL * num[v] + ((par[v] < 0) ? 0 : sum(par[v])) % mod;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(par, -1, sizeof par);
	int n, res = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		if (k == 0)
			continue;
		int mx = -1, mxsz = 0, mxval;
		vec.clear();
		for (int t = 0; t < k; t++) {
			int v, x;
			cin >> v >> x;
			--v;
			vec.push_back(MP(root(v), (x + sum(v)) % mod));
			res = (1LL * res + vec.back().S) % mod;
			if (-par[vec.back().F] > mxsz)	{
				mx = vec.back().F;
				mxval = vec.back().S;
				mxsz = -par[vec.back().F];
			}
		}
		num[mx] += mxval;
		par[i] = mx;
		num[i] -= mxval;
		for (auto x : vec) {
			int u = x.F, val = x.S;
			if (u == mx)
				continue;
			par[mx] += par[u];
			par[u] = mx;
			num[u] = (1LL * num[u] + val - mxval) % mod;
		}
	}
	cout << (res + mod) % mod << "\n";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define F first
#define S second
#define MP make_pair
const int maxn = 1e5+9;
const ll mod = 1e9+7;

vector <pii> vec;
int num[maxn], par[maxn];

int root (int v) {
	return ((par[v] < 0) ? v : root(par[v]));
}

int sum (int v) {
	return 1LL * num[v] + ((par[v] < 0) ? 0 : sum(par[v])) % mod;
}

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(par, -1, sizeof par);
	int n, res = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		if (k == 0)
			continue;
		int mx = -1, mxsz = 0, mxval;
		vec.clear();
		for (int t = 0; t < k; t++) {
			int v, x;
			cin >> v >> x;
			--v;
			vec.push_back(MP(root(v), (x + sum(v)) % mod));
			res = (1LL * res + vec.back().S) % mod;
			if (-par[vec.back().F] > mxsz)	{
				mx = vec.back().F;
				mxval = vec.back().S;
				mxsz = -par[vec.back().F];
			}
		}
		num[mx] += mxval;
		par[i] = mx;
		num[i] -= mxval;
		for (auto x : vec) {
			int u = x.F, val = x.S;
			if (u == mx)
				continue;
			par[mx] += par[u];
			par[u] = mx;
			num[u] = (1LL * num[u] + val - mxval) % mod;
		}
	}
	cout << res << "\n";
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 100 * 1000 + 10;
const ll md = 1e9 + 7;
ll n, par[MAXN], d[MAXN], s = 0;

ll find(int a)
{
	if(a == par[a])
		return a;
	if(par[par[a]] != par[a])
	{
		d[a] += d[par[a]];
		d[a] %= md;
	}
	return par[a] = find(par[a]);
}

void uni(ll i, ll v, ll x)
{
	//cout << "UNI " << endl;
	ll r = find(v);
	//cout << "2222" << endl;
	d[r] = d[v] + x;
	//cout << "333" << endl;
	//cout << "&*(&&*&^%)" << d[r] << " ";
	d[r] %= md;
	//cout << "????" << endl;
	s += d[r];
	s %= md;
	par[r] = i;
	return;
}/////

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	ll k, v, x;
	for(int i = 0; i < n; i++)
		par[i] = i;
	for(int i = 0; i < n; i++)
	{
		cin >> k;
		for(int j = 0; j < k; j++)
		{
			cin >> v >> x;
			v--;
			uni(i, v, x);
		}
	}
	cout << s << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 100 * 1000 + 10;
const ll md = 1000000007;
ll n, par[MAXN], d[MAXN], s = 0;

ll find(int a)
{
	if(a == par[a])
		return a;
	if(par[par[a]] != par[a])
	{
		d[a] += d[par[a]];
		d[a] += md;
		d[a] %= md;
	}
	return par[a] = find(par[a]);
}

void uni(ll i, ll v, ll x)
{
	ll r = find(v);
	d[r] = d[v] + x;
	d[r] += md;
	d[r] %= md;
	s += d[r];
	s += md;
	s %= md;
	par[r] = i;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	ll k, v, x;
	for(int i = 1; i <= n; i++)
		par[i] = i;
	for(int i = 1; i <= n; i++)
	{
		cin >> k;
		for(int j = 0; j < k; j++)
		{
			cin >> v >> x;
			//v--;
			uni(i, v, x);
		}
	}
	cout << s << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 100 * 1000 + 10;
const ll md = 1000000007;
ll n, par[MAXN], d[MAXN], s = 0;
bool sl[MAXN];

ll find(ll a)
{
	if(a == par[a])
	{
		sl[a] = true;
		return a;
	}
	sl[a] = false;
	ll tmp = find(par[a]);
	//cout << "a " << a << "   para " << par[a] << "   sl " << sl[par[a]] << endl;
	if(!sl[par[a]])
	{
		d[a] += d[par[a]];
		d[a] %= md;
	}
	par[a] = tmp;
	return par[a];
}

void uni(ll a, ll b, ll w)
{
	ll r = find(b);
	d[r] = d[b] + w + md;
	d[r] %= md;
	par[r] = a;
	s += d[r];
	s %= md;
	//cout << "r " << r << "   parr " << par[r] << endl;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
		par[i] = i;
	for(int i = 1; i <= n; i++)
	{
		ll k;
		cin >> k;
		while(k--)
		{
			ll v, x;
			cin >> v >> x;
			uni(i, v, x);
		}
		/*cout << "!!!!!!" << endl;
		for(int j = 1; j <= n; j++)
		{
			cout << "JJJJ " << j << endl;
			ll tmp = find(j);
		}
		for(int j = 1; j <= n; j++)
			cout << d[j] << " ";
		cout << endl;
		for(int j  = 1; j <= n; j++)
			cout << par[j] << " ";
		cout << endl << endl;*/
	}
	cout << s << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 100 * 1000 + 10;
const ll md = 1000000007;
ll n, par[MAXN], d[MAXN], s = 0;

ll find(ll a)
{
	if(a == par[a])
		return a;
	if(par[par[a]] != par[a])
	{
		d[a] += d[par[a]];
		d[a] %= md;
	}
	par[a] = find(par[a]);
	return par[a];
}

void uni(ll a, ll b, ll w)
{
	ll r = find(b);
	d[r] = d[b] + w + md;
	d[r] %= md;
	par[r] = a;
	s += d[r];
	s %= md;
	return;
}

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i = 1; i <= n; i++)
		par[i] = i;
	for(int i = 1; i <= n; i++)
	{
		ll k;
		cin >> k;
		while(k--)
		{
			ll v, x;
			cin >> v >> x;
			uni(i, v, x);
		}
	}
	cout << s << endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long int ll;

const int MAXN = 100 * 1000 + 10;
const ll md = 1e9 + 7;
ll n, par[MAXN], d[MAXN], s = 0;

ll find(int a)
{
	if(a == par[a])
		return a;
	if(par[par[a]] != par[a])
	{
		d[a] += d[par[a]];
		d[a] %= md;
	}
	return par[a] = find(par[a]);
}

void uni(ll i, ll v, ll x)
{
	//cout << "UNI " << endl;
	ll r = find(v);
	//cout << "2222" << endl;
	d[r] = d[v] + x;
	d[r] += md;
	//cout << "333" << endl;
	//cout << "&*(&&*&^%)" << d[r] << " ";
	d[r] %= md;
	//cout << "????" << endl;
	s += d[r];
	s %= md;
	par[r] = i;
	return;
}/////

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n;
	ll k, v, x;
	for(int i = 0; i < n; i++)
		par[i] = i;
	for(int i = 0; i < n; i++)
	{
		cin >> k;
		for(int j = 0; j < k; j++)
		{
			cin >> v >> x;
			v--;
			uni(i, v, x);
		}
	}
	cout << s << endl;
	return 0;
}


#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define Left (h<<1),l,(l+r)>>1
#define Right ((h<<1)|1),((l+r)>>1)+1,r
#define ll long long
#define pb push_back
#define F first
#define S second
using namespace std;
const int N=1e5+5;
ll ans,g[4*N],mod=1e9+7,x;
bool f[N];
ll timer,in[N],out[N],A,B,r,u,n,p[N];
vector < pair < ll , pair < ll , ll > > > v[N];

int P(int x) {
	if (p[x]==x) return x;
	return p[x]=P(p[x]);
}

void Uni(int a,int b,ll x) {
	A=P(a);
	B=P(b);
	v[B].pb({A,{a,x}});
	f[A]=1;
	p[A]=B;
}

void Upd(Tree,int L,int R,ll dl) {
	if (r<L || R<l) return;
	if (L<=l && r<=R) { g[h]=(g[h]+dl)%mod; return ; }
	Upd(Left,L,R,dl),Upd(Right,L,R,dl);
}

ll Get(Tree,int id) {
	if (r<id || id<l) return 0;
	if (l==id && r==id) return g[h];
	return (Get(Left,id)+Get(Right,id)+g[h])%mod;
}

void Dfs(int x) {
	in[x]=++timer;
	for (int i=0; i<v[x].size(); i++) {
		ll to=v[x][i].F,cost=v[x][i].S.S,Qu=v[x][i].S.F;
		Dfs(to);
		ll edge=(Get(1,1,n,in[Qu])+cost)%mod;
		ans=(ans+edge)%mod;
		Upd(1,1,n,in[to],out[to],edge);
	}
	out[x]=timer;
}

main () {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;

	for (int i=1; i<=n; i++)
		p[i]=i;

	for (int i=1; i<=n; i++) {
		cin>>r;
		for (int j=1; j<=r; j++) {
			cin>>u>>x;
			Uni(u,i,x);
		}
	}

	for (int i=1; i<=n; i++)
		if (!f[i]) Dfs(i);

	cout<<(ans+mod)%mod<<endl;
}


/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int to[SIZE];
struct Union_Find{
    int d[SIZE];
    LL dis[SIZE];
    void init(int n){
        REP(i,n)d[i]=i,dis[i]=0;
    }
    bool is_root(int x){return d[x]==x;}
    int find(int x){
        if(x==d[x])return x;
        int y=d[x];
        d[x]=find(y);
        ADD(dis[x],dis[y]);
        return d[x];
    }
    LL get_dis(int x){
        find(x);
        return dis[x];
    }
    bool uu(int x,int y,LL v){
        x=find(x);
        y=find(y);
        if(x==y)return 0;
        ADD(dis[x],v);
        d[x]=y;
        return 1;
    }
}U;
VI e[SIZE];
int main(){
    int n;
    R(n);
    U.init(n);
    MS1(to);
    REP(i,n){
        int k;
        R(k);
        REP(j,k){
            int v;
            LL x;
            R(v,x);
            v--;
            ADD(x,U.get_dis(v));
            to[U.find(v)]=i;
            U.uu(U.find(v),i,x);
        }
    }
    LL an=0;
    REP(i,n){
        if(to[i]!=-1){
            U.find(i);
            U.find(to[i]);
            ADD(an,U.dis[i]-U.dis[to[i]]);
        }
    }
    W(an);
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define L first
#define R second
#define debug(x) cerr<<#x<<" :"<<x<<"\n"
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie();
#define int long long

const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;
const int INF = 1e9 + 7;
const int mlog = 21;
const int SQ = 400;

int f[maxn],we[maxn];

int ans = 0;

int get(int v)
{
	if(f[v] == v)
		return v;

	int vv = f[v];
	f[v] = get(f[v]);

	we[v] = (we[v] + we[vv])%mod;

	return f[v];
}

void merge(int v,int i,int x)
{
	int vv = get(v);
	int ii = get(i);

	if(vv == ii)
		return;

	ans = (ans+we[v] + x)%mod;

	f[vv] = ii;
	we[vv]  =(we[v] + x)%mod;
}

int32_t main()
{
	FAST;

	int n;
	cin>>n;

	for(int i=1;i<=n;i++)
	{
		int k;
		cin>>k;

		f[i] = i;
		for(int j=0;j<k;j++)
		{
			int v,x;
			cin>>v>>x;

			merge(v,i,x);
		}
	}

	cout<<(ans + mod)%mod<<"\n";

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long ans = 0;
int p[100005];
long long d[100005];
pair<int, int> find(int x) {
    if(x == p[x])
        return {x, d[x]};
    else {
        auto [r, dd] = find(p[x]);
        p[x] = r;
        d[x] = (dd + d[x]) % mod;
        return {p[x], d[x]};
    }
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        p[i] = i;
        d[i] = 0;
        int k;
        cin >> k;
        for(int j = 1; j <= k; ++j) {
            int v, x;
            cin >> v >> x;

            auto [r, dd] = find(v);
            p[r] = i;
            d[r] = (dd + x) % mod;
            ans = (ans + dd + x) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long ans = 0;
int p[100005];
long long d[100005];
pair<int, int> find(int x) {
    if(x == p[x])
        return {x, d[x]};
    else {
        auto [r, dd] = find(p[x]);
        p[x] = r;
        d[x] = (dd + d[x]) % mod;
        return {p[x], d[x]};
    }
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        p[i] = i;
        d[i] = 0;
        int k;
        cin >> k;
        for(int j = 1; j <= k; ++j) {
            int v, x;
            cin >> v >> x;
            if(x < 0) x += mod;

            auto [r, dd] = find(v);
            p[r] = i;
            d[r] = (dd + x) % mod;
            ans = (ans + dd + x) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long ans = 0;
int p[100005];
long long d[100005];
pair<int, int> find(int x) {
    if(x == p[x])
        return {x, d[x]};
    else {
        auto [r, dd] = find(p[x]);
        p[x] = r;
        d[x] = (dd + d[x]) % mod;
        return {p[x], d[x]};
    }
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1; i <= n; ++i) {
        p[i] = i;
        d[i] = 0;
        int k;
        cin >> k;
        for(int j = 1; j <= k; ++j) {
            int v, x;
            cin >> v >> x;

            auto [r, dd] = find(v);
            p[r] = i;
            d[r] = dd + x;
            ans = (ans + dd + x) % mod;
        }
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (ll) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const ll inf = numeric_limits <ll>::max() >> 1;
const ll N = 1e5 + 1;
const ll mod = 1e9 + 7;
ll n, ans;

struct Dsu {
    ll par[N];
    ll cnt[N];
    ll wgt[N];
} dsu;

ll root(ll u) {
    if(dsu.par[u] == u) {
        return u;
    } else {
        ll w = dsu.wgt[u];
        ll p = dsu.par[u];
        ll v = root(p);
        dsu.par[u] = v;
        dsu.wgt[u] = dsu.wgt[p] + w;
        dsu.wgt[u] %= mod;
        return v;
    }
}

void unite(ll u, ll v) {
    if(dsu.cnt[u] < dsu.cnt[v]) {
        swap(u, v);
    }
    dsu.cnt[u] += dsu.cnt[v];
    dsu.par[v] = u;
}

void input() {
    cin >> n;
    for(ll i = 1; i <= n; ++i) {
        dsu.par[i] = i;
        dsu.cnt[i] = 1;
    }
}

void solve() {
    for(ll i = 1; i <= n; ++i) {
        ll k; cin >> k;
        while(k--) {
            ll v; cin >> v;
            ll w; cin >> w;
            ll r = root(v);
            dsu.par[r] = i;
            dsu.wgt[r] = dsu.wgt[v] + w;
            dsu.wgt[r] %= mod;
            ans += dsu.wgt[r];
            ans %= mod;
        }
    }
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (ll) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const ll inf = numeric_limits <ll>::max() >> 1;
const ll N = 1e5 + 1;
const ll mod = 1e9 + 7;
ll n, ans;

struct Dsu {
    ll par[N];
    ll cnt[N];
    ll wgt[N];
} dsu;

ll root(ll u) {
    if(dsu.par[u] == u) {
        return u;
    } else {
        ll w = dsu.wgt[u];
        ll p = dsu.par[u];
        ll v = root(p);
        dsu.par[u] = v;
        dsu.wgt[u] = dsu.wgt[p] + w;
        return v;
    }
}

void unite(ll u, ll v) {
    if(dsu.cnt[u] < dsu.cnt[v]) {
        swap(u, v);
    }
    dsu.cnt[u] += dsu.cnt[v];
    dsu.par[v] = u;
}

void input() {
    cin >> n;
    for(ll i = 1; i <= n; ++i) {
        dsu.par[i] = i;
        dsu.cnt[i] = 1;
    }
}

void solve() {
    for(ll i = 1; i <= n; ++i) {
        ll k; cin >> k;
        while(k--) {
            ll v; cin >> v;
            ll w; cin >> w;
            ll r = root(v);
            dsu.par[r] = i;
            dsu.wgt[r] = dsu.wgt[v] + w;
            ans += dsu.wgt[r];
            ans %= mod;
        }
    }
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/priority_queue.hpp>
//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")
//#pragma GCC target("avx2")

#define deb(x) cout << #x << " = " << x << "\n"
#define all(x) (x).begin(), (x).end()
#define len(x) (ll) x.size()
#define lsb(x) (x) & -(x)
#define l(x) (x << 1) + 1
#define r(x) (x << 1) + 2

#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pii;
typedef pair <ld, ld> pld;
typedef pair <ll, ll> pll;

template <class T1, class T2 = less <T1>> using pb_heap = __gnu_pbds::priority_queue <T1, T2, binary_heap_tag>;
template <class T1, class T2 = null_type, class T3 = less <T1>> using pb_map = tree <T1, T2, T3, rb_tree_tag, tree_order_statistics_node_update>;
template <class T1, class T2 = null_type, class T3 = hash <T1>> using pb_umap = gp_hash_table <T1, T2, T3>;
template <class T1, class T2, class T3 = hash <T1>> using umap = unordered_map <T1, T2, T3>;
template <class T> using uset = unordered_set <T>;
template <class T> using vec = vector <T>;

const ll infll = numeric_limits <ll>::max() >> 1;
const ll inf = numeric_limits <ll>::max() >> 1;
const ll N = 1e5 + 1;
const ll mod = 1e9 + 7;
ll n, ans;

struct Dsu {
    ll par[N];
    ll cnt[N];
    ll wgt[N];
} dsu;

ll root(ll u) {
    if(dsu.par[u] == u) {
        return u;
    } else {
        ll w = dsu.wgt[u];
        ll p = dsu.par[u];
        ll v = root(p);
        dsu.par[u] = v;
        dsu.wgt[u] = dsu.wgt[p] + w;
        return v;
    }
}

void unite(ll u, ll v) {
    if(dsu.cnt[u] < dsu.cnt[v]) {
        swap(u, v);
    }
    dsu.cnt[u] += dsu.cnt[v];
    dsu.par[v] = u;
}

void input() {
    cin >> n;
    for(ll i = 1; i <= n; ++i) {
        dsu.par[i] = i;
        dsu.cnt[i] = 1;
    }
}

void solve() {
    for(ll i = 1; i <= n; ++i) {
        ll k; cin >> k;
        while(k--) {
            ll v; cin >> v;
            ll w; cin >> w;
            ll r = root(v);
            dsu.par[r] = i;
            dsu.wgt[r] = dsu.wgt[v] + w;
            ans += dsu.wgt[r];
        }
    }
    ans %= mod;
    ans += mod;
    ans %= mod;
    cout << ans << "\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    input();
    solve();
}


#include <bits/stdc++.h>
using namespace std;

const int N = 1e5 + 1;
const long long MOD = 1e9 + 7;

int p[N];
long long sum[N];
long long ans = 0;

long long add(long long a, long long b) {
    return (((a + b) % MOD) + MOD) % MOD;
}

void init(int n) {
    for (int v = 1; v <= n; v++) {
        p[v] = v;
    }
}

int findParent(int v) {
    if (p[v] == v)
        return v;
    else {
        int u = findParent(p[v]);
        sum[v] = add(sum[v], sum[p[v]]);
        p[v] = u;
        return u;
    }
}

void addEdge(int v, int u, int x) {
    int np = findParent(v);
    p[np] = u;
    sum[np] = add(sum[v], x);
    ans = add(ans, sum[np]);
}

void solve() {
    int n;
    cin >> n;
    init(n);
    for (int i = 1; i <= n; i++) {
        int k, v, x;
        cin >> k;
        for (int j = 0; j < k; j++) {
            int v, x;
            cin >> v >> x;
            addEdge(v, i, x);
        }
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solve();
    return 0;
}


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
bool isPrime(long long int x) {
	if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
	for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;
}

#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"
#define debug(M) for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cout<<(M)[i][j]<< " ";}cout<<endl;}
//#define LONG_LONG_MAX  9223372036854775807
//#define LONG_LONG_MIN   -9223372036854775807
//#define max3(a, b, c) max(a, max(b, c))
//#define min3(a, b, c) min(a, min(b, c))
//#define PI 3.14159265
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}

const int INF = int(1e17 + 7);

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}
int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

const int modulo = 1e9 + 7;
const int MAXN = 1e5 + 5;

vector<pair<int, int>> gr[MAXN];

int const maxn = 2e5 + 5;
int par[maxn];
int rnk[maxn];
vector<int> del;
vector<int> add;
int used[maxn];

int maxS = 51;
vector<int> cnt(maxn,0);
vector<string> S;

int getpar(int x) {
	//return par[x] == x ? x : par[x] = getpar(par[x]);
	if(par[x] == x)
	 return x;
	int res = getpar(par[x]);
	cnt[x] = (cnt[x] + cnt[par[x]]) % modulo;
	return par[x] = res;
}

int ans1 = 0, ans2 = 0;

void uni(int x, int y) {
	x = getpar(x);
	y = getpar(y);
	if (x != y) {
		par[y] = x;
	}
}

bool compa(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

int32_t main()
{
	iota(begin(par), end(par), 0);
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<pair<int,int>>> e(n);
	for (int i = 1; i <= n; ++i) {
		int k;
		cin >> k;
		forj(k) {
			int v, w;
			cin >> v >> w;
			v = abs(v); w = abs(w);
			int pv = getpar(v);
			int cur = cnt[v];
			cur = (cur + w) % modulo;
			ans = (ans + cur) % modulo;
			cnt[pv] = (cnt[pv] + cur) % modulo;
			par[pv] = i;
		}

	}
	cout << ans;
}
/* Tue Feb 11 2020 00:11:32 GMT+0300 (MSK) */


#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pld pair<ld, ld>
#define mp make_pair
using namespace std;

const int inf = int(1e9 + 7);
const double eps = 1e-7;

vector<tuple<int, int, int>> ed;
vector<pll> par;
vector<int> rnk;

int n, m;

pll getpar(int x) {
    pll p = par[x];
    if(p.second == x) {
        return p;
    } else {
        pll c = getpar(p.second);
        return mp((c.first + p.first) % inf, c.second);
    }
}

void uni(int x, int y, int w) {
    pll b = getpar(x);
    par[b.second] = mp((b.first + w) % inf, y);
}

int main() {
    int a, b, c, k;
    cin >> n;

    //ed.resize(m);
    par.resize(n + 1);
    rnk.assign(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        par[i] = mp(0, i);
    }

    for (auto &t : ed) {
        cin >> get<1>(t) >> get<2>(t) >> get<0>(t);
    }
    sort(ed.begin(), ed.end());

    for(int i = 1; i <= n; i++) {
        cin >> k;
        for(int j = 0; j < k; j++) {
            cin >> a >> b;
            uni(a, i, b);
        }
    }

    ll sum = 0;
    vector<char> used(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        int cur = i;
        while(cur != par[cur].second && used[cur] == 0) {
            sum = (sum + par[cur].first) % inf;
            used[cur] = 1;
            cur = par[cur].second;
        }
    }

    cout << sum << endl;

    return 0;
}
/* Sat Feb 01 2020 12:58:24 GMT+0300 (MSK) */


#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
bool isPrime(long long int x) {
	if (x <= 4 || x % 2 == 0 || x % 3 == 0) return x == 2 || x == 3;
	for (int i = 5; i * i <= x; i += 6) if (x % i == 0 || x % (i + 2) == 0) return 0; return 1;
}

#define ff first
#define ss second
#define int ll
#define fori(n) for (int i = 0; i < (n); i++)
#define forj(n) for (int j = 0; j < (n); j++)
#define endl "\n"
#define debug(M) for(int i = 0; i < n; i++){for(int j = 0; j < n; j++){cout<<(M)[i][j]<< " ";}cout<<endl;}
//#define LONG_LONG_MAX  9223372036854775807
//#define LONG_LONG_MIN   -9223372036854775807
//#define max3(a, b, c) max(a, max(b, c))
//#define min3(a, b, c) min(a, min(b, c))
//#define PI 3.14159265
using namespace std;

inline void boostIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout.precision(10);
}

const int INF = int(1e17 + 7);

int gcd(int a, int b)
{
	if (b == 0) return a;
	a %= b;
	return gcd(b, a);
}

int optpow(int a, int b, int k) {
	if (b == 0)
		return 1;
	int tmp = optpow(a, b / 2, k);
	if (b % 2 == 1) {
		return ((tmp*tmp) % k * a) % k;
	}
	else {
		return (tmp*tmp) % k;
	}
}
int qckpow(int a, int b) {
	if (b == 0)
		return 1;
	int tmp = qckpow(a, b / 2);
	if (b % 2 == 1) {
		return ((tmp*tmp) * a);
	}
	else {
		return (tmp*tmp);
	}
}

const int modulo = 1e9 + 7;
const int MAXN = 1e5 + 5;

vector<pair<int, int>> gr[MAXN];

int const maxn = 2e5 + 5;
int par[maxn];
int rnk[maxn];
vector<int> del;
vector<int> add;
int used[maxn];

int maxS = 51;
vector<int> cnt(maxn,0);
vector<string> S;

int getpar(int x) {
	//return par[x] == x ? x : par[x] = getpar(par[x]);
	if(par[x] == x)
	 return x;
	int res = getpar(par[x]);
	cnt[x] = (cnt[x] + cnt[par[x]]) % modulo;
	return par[x] = res;
}

int ans1 = 0, ans2 = 0;

void uni(int x, int y) {
	x = getpar(x);
	y = getpar(y);
	if (x != y) {
		par[y] = x;
	}
}

bool compa(pair<int, int> p1, pair<int, int> p2) {
	if (p1.ss == p2.ss)
		return p1.ff < p2.ff;
	return p1.ss < p2.ss;
}

int32_t main()
{
	iota(begin(par), end(par), 0);
	int n;
	cin >> n;
	int ans = 0;
	vector<vector<pair<int,int>>> e(n);
	for (int i = 1; i <= n; ++i) {
		int k;
		cin >> k;
		forj(k) {
			int v, w;
			cin >> v >> w;
			while (w < 0)
				w += modulo;
			while (w >= modulo)
				w -= modulo;
			int pv = getpar(v);
			int cur = cnt[v];
			cur = (cur + w) % modulo;
			ans = (ans + cur) % modulo;
			cnt[pv] = (cnt[pv] + cur) % modulo;
			par[pv] = i;
		}

	}
	cout << ans;
}
/* Tue Feb 11 2020 00:15:14 GMT+0300 (MSK) */


#include <bits/stdc++.h>

using namespace std;
#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

double PI=3.141592653589793;

const int P=1e9+7;
//Modular arithmetic
class mint{
	public:
		static int init_siz;
		static vector<mint> inverse,factorial;
		static int mintP;
		int n;
		static mint exp(mint a, long long e) {
			mint res = 1; while (e) { if (e&1) res *= a; a *= a; e >>= 1; }
			return res;
		}
		static void init(int n){
			init_siz=n;
			inverse.resize(n+1);factorial.resize(n+1);
			factorial[0] = 1;
			for (int i = 1; i <= n; i++) factorial[i] = factorial[i - 1] * i;
			inverse[n]=exp(factorial[n],mintP-2);
			for (int i = n-1; i>=0; i--) inverse[i] = inverse[i+1] * (i+1);
		}
		static mint inv(mint const& a){return (init_siz>=a.n? inverse[a.n]*(a.n>1?fac(a-1):1):exp(a,mintP-2));}
		static mint cinv(mint const& a){return (init_siz>=a.n? inverse[a.n]:exp(fac(a),mintP-2));}
		static mint fac(mint const& a){
			if(init_siz>=a.n) return factorial[a.n];
			else{
				mint out=1;
				for(int i=0;i<a.n;i++) out*=(i+1);
				return out;
			}
		}
		mint(long long val = 0) {n=val%mintP;if(n<0) n+=mintP;}
		mint& operator+=(mint const& b) {n += b.n; if (n >= mintP) n -= mintP; return *this;}
		mint& operator-=(mint const& b) {n -= b.n; if (n < 0) n += mintP;return *this;}
		mint& operator*=(mint const& b) {n = (long long)n * b.n % mintP;return *this;}
		mint exp(long long e) {return exp(*this,e);}
		mint inv(){return inv(*this);}
		mint& operator/=(mint const& b){ return *this *=inv(b);}
		friend std::ostream& operator<<(std::ostream& os,mint const& a) {return os << (a.n<0?a.n+mintP:a.n);}
		friend mint operator+(mint a, mint const b) { return a += b; }
		friend mint operator-(mint a, mint const b) { return a -= b; }
		friend mint operator-(mint const a) { return 0 - a; }
		friend mint operator*(mint a, mint const b) { return a *= b; }
		friend mint operator/(mint a, mint const b) { return a /= b; }
		friend bool operator==(mint const& a, mint const& b) {return a.n == b.n;}
		friend bool operator!=(mint const& a, mint const& b) {return a.n != b.n;}
};
int mint::init_siz=0;
int mint::mintP=P;
vector<mint> mint::factorial,mint::inverse;

// Fenwick Tree
template<typename T>
class fenwick{
	private:
		int g(int i) { return i & (i + 1); }
		int h(int i) { return i | (i + 1); }
		int N;
		vector<T> tree;
		T lambda(T a, T b) {return a+b;}
	public:
		fenwick(int siz){
			N=siz;
			tree.resize(siz);
		}
		void add(int pos,T delta) {
			for(;pos<N;pos=h(pos)) tree[pos]=lambda(tree[pos],delta);
		}
		T sum(int l) {
			T out = 0;
			for(;l >= 0;l=g(l)-1) out=lambda(out,tree[l]);
			return out;
		}
};

// Disjoint Set Union
class dsu {
	private:
		int N;
		vector<int> par;
		int getpar(int v) {
			if (par[v] != v) par[v] = getpar(par[v]);
			return par[v];
		}
		pair<int, int> getparhei(int v) {
			if (par[v] == v)
				return {v, 0};
			else {
				auto temp = getparhei(par[v]);
				temp.second++;
				return temp;
			}
		}
	public:
		dsu(int siz) {
			N = siz;
			par.resize(N);
			iota(par.begin(), par.end(), 0);
		}
		int id(int v) { return getpar(v); }
		void merge(int v1, int v2) {
			auto par1 = getparhei(v1);
			auto par2 = getparhei(v2);
			if (par1.second < par2.second) swap(par1, par2);
			par[par2.first] = par1.first;
		}
		bool same(int v1, int v2) { return getpar(v1) == getpar(v2); }
};

const int mx=1e5+1;
int par[mx]={},gcnt=0,st[mx]={},ed[mx]={},rst[mx]={};
bool done[mx]={};
vector<int> adj[mx],xs[mx];
vector<mint> wei[mx];

void dfs(int u){
	done[u]=1;
	st[u]=gcnt++;
	rst[st[u]]=u;
	for(auto v:adj[u]){
		dfs(v);
	}
	ed[u]=gcnt-1;
}

void solve(){
	int n;
	cin >> n;
	dsu id(n);
	iota(par,par+mx,0);
	forn(i,n){
		int k;
		cin >> k;
		forn(ind,k){
			int v,x;
			cin >> x >> v;
			x--;
			adj[i].pb(par[id.id(x)]);
			wei[i].pb(v);
			xs[i].pb(x);
			id.merge(x,i);
		}
		par[id.id(i)]=i;
	}
//	forn(i,n){
//		cout << "A===============================\n";
//		cout << i << '\n';
//		for(auto v:adj[i]) cout  << v << ' ';
//		cout << '\n';
//	}
//	return;
	for(int i=n-1;i>=0;i--){
		if(done[i]) continue;
		dfs(i);
	}
	fenwick<mint> tree(n+1);

	mint ans=0;

//	cout << '\n';
//	forn(i,n) cout << st[i] << ' ' << ed[i] << '\n';

	forn(i,n){
		int k=sz(adj[i]);
//		cout << "A=======================\n";
//		cout << i << '\n';
		forn(j,k){
			mint val=wei[i][j]+tree.sum(st[xs[i][j]]);
//			cout << xs[i][j] << '\n';
//			cout << adj[i][j] << ' ' << wei[i][j] << ' ' << val << '\n';
//			cout << st[adj[i][j]]-1 << ' ' << ed[adj[i][j]] << '\n';
			ans+=val;
			tree.add(st[adj[i][j]],val);
			tree.add(ed[adj[i][j]]+1,-val);
//			cout << "B=======================\n";
//			forn(i,n) cout << tree.sum(i) << ' ';
//			cout << '\n';
		}
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
	//	cout << "Case #" << cid << ": ";
		solve();
	}
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
#define int ll
typedef pair<int, int> ii;
typedef vector <int> vi;
typedef vector<ii> vii;
typedef vector <vii> vvii;
typedef vector<vi> vvi;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int cp[100010]; //components
int dis[100010]; //components
const int MOD = 1e9+7;

int find(int x){
    if (cp[x] == x) return x;
    int par = cp[x];
    cp[x] = find(cp[x]);
    dis[x] += dis[par];
    dis[x] = (dis[x]+2*MOD)%MOD;
    return par;
}

void union_(int x, int y){ cp[find(x)] = find(y);}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; ++i) cp[i] = i;
    for (int j = 0; j < n; ++j) {
        int k; cin >> k;
        for (int i = 0; i < k; ++i) {
            int v, x; cin >> v >> x; v--;
            int u = find(v);
            int d = dis[v];
            dis[u] = (d+x+2*MOD)%MOD;
            ans = (ans + dis[u]+2*MOD)%MOD;
            union_(u, j);
            find(v);
        }
        cout << "\n";
    }
    cout << ans << "\n";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef long long ll;
#define int ll
typedef pair<int, int> ii;
typedef vector <int> vi;
typedef vector<ii> vii;
typedef vector <vii> vvii;
typedef vector<vi> vvi;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int cp[100010]; //components
int dis[100010]; //components
const int MOD = 1e9+7;

int find(int x){
    if (cp[x] == x) return x;
    int par = cp[x];
    cp[x] = find(cp[x]);
    dis[x] += dis[par];
    dis[x] = (dis[x]+MOD)%MOD;
    return cp[x];
}

void union_(int x, int y){ cp[find(x)] = find(y);}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; ++i) cp[i] = i;
    for (int j = 0; j < n; ++j) {
        int k; cin >> k;
        for (int i = 0; i < k; ++i) {
            int v, x; cin >> v >> x; v--;
            int u = find(v);
            int d = dis[v];
            dis[u] = (d+x+MOD)%MOD;
            ans = (ans + dis[u]+MOD)%MOD;
            union_(u, j);
            find(v);
        }
    }
    cout << ans << "\n";
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define ff               first
#define ss               second
#define pb               push_back
#define all(x)           (x).begin(), (x).end()
#define mem0(x)          memset(x, 0, sizeof (x))
#define mem1(x)          memset(x, -1, sizeof (x))

typedef pair<int, int> ii;
typedef vector <int> vi;
typedef vector<ii> vii;
typedef vector <vii> vvii;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector <ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;

int cp[100010]; //components
int dis[100010]; //components
const int MOD = 1e9+7;

int find(int x){
    if (cp[x] == x) return x;
    int par = cp[x];
    cp[x] = find(cp[x]);
    dis[x] += dis[par];
    return par;
}

void union_(int x, int y){ cp[find(x)] = find(y);}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    ll ans = 0;
    for (int i = 0; i < n; ++i) cp[i] = i;
    for (int j = 0; j < n; ++j) {
        int k; cin >> k;
        for (int i = 0; i < k; ++i) {
            int v, x; cin >> v >> x; v--;
            int u = find(v);
            int d = dis[v];
            dis[u] = (d+x)%MOD;
            ans = (ans + dis[u])%MOD;
            union_(u, j);
        }
    }
    cout << ans << "\n";
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int	n;
long long sum[100007];
int par[100007];
long long wei[100007];
long long m = 0;
long long Mod = 1e9 + 7;
int getpar(int x) {
	return par[x] == x ? x : par[x] = getpar(par[x]);
}
long long gett(int x) {
	if (par[x] == x) {
		return 0;
	}
	return (wei[x] + gett(par[x])+Mod)%Mod;
}
void uni(int x, int y, long long w) {
	y = getpar(y);
	par[y] = x;
	wei[y] = w;
	m = (m+w+Mod)%Mod;
}
int main()
{
    cin>>n;
	for (int i = 1; i <= n; i++)
	{
		par[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		int k;
		cin >> k;
		for (int j = 1;j <= k; j++)
		{
			int v;
			long long x;
			cin >> v >> x;
			uni(i, v,x+gett(v));
		}
	}
	cout << m;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int	n;
long long sum[100007];
int par[100007];
long long wei[100007];
long long m = 0;
long long Mod = 1e9 + 7;
int getpar(int x) {
	return par[x] == x ? x : par[x] = getpar(par[x]);
}
long long gett(int x) {
	if (par[x] == x) {
		return 0;
	}
	return (wei[x] + gett(par[x]))%Mod;
}
void uni(int x, int y, long long w) {
	y = getpar(y);
	par[y] = x;
	wei[y] = w;
	m = (m+w)%Mod;
}
int main()
{
    cin>>n;
	for (int i = 1; i <= n; i++)
	{
		par[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		int k;
		cin >> k;
		for (int j = 1;j <= k; j++)
		{
			int v;
			long long x;
			cin >> v >> x;
			long long a = x + gett(v);
			uni(i, v,a);
		}
	}
	cout << m;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int	n;
long long sum[100007];
long long par[100007];
long long wei[100007];
long long m = 0;
long long Mod = 1e9 + 7;
long long getpar(int x) {
	if (par[x] == x)
		return x;
	int res = getpar(par[x]);
	sum[x] = (sum[par[x]] + sum[x] + Mod) % Mod;
	return par[x] = res;
}
void uni(long long x, long long y,long long w) {
	int a = getpar(y);
	if(y!=a)
		sum[a]+=w;
	w += sum[y];
	par[y] = x;
	sum[y] += w;
	m = (m+sum[y]+Mod)%Mod;
}
int main()
{
    cin>>n;
	for (int i = 1; i <= n; i++)
	{
		par[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		int k;
		cin >> k;
		for (int j = 1;j <= k; j++)
		{
			int v;
			long long x;
			cin >> v >> x;
			uni(i, v,x);
		}
	}
	cout << m;
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int	n;
long long sum[100007];
long long par[100007];
long long wei[100007];
long long m = 0;
long long Mod = 1e9 + 7;
long long getpar(int x) {
	if (par[x] == x)
		return x;
	int res = getpar(par[x]);
	sum[x] = (sum[par[x]] + sum[x] + Mod) % Mod;
	return par[x] = res;
}
void uni(long long x, long long y,long long w) {
	int a = getpar(y);
	if (y != a) {
		w = (sum[y] + w + Mod) % Mod;
		sum[a] += w;
	}
	par[y] = x;
	par[a] = x;
	sum[y] = (sum[y]+w+Mod)%Mod;
	m = (m+w+Mod)%Mod;
}
int main()
{
    cin>>n;
	for (int i = 1; i <= n; i++)
	{
		par[i] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		int k;
		cin >> k;
		for (int j = 1;j <= k; j++)
		{
			int v;
			long long x;
			cin >> v >> x;
			uni(i, v,x);
		}
	}
	cout << m;
}


using System;
using System.Collections.Generic;
using System.Text;

public class taskA
{
    static void Main(string[] args)
    {
        string inp = Console.ReadLine();
        string[] spl = inp.Split(' ');

        int n = int.Parse(spl[0]);

        int[] x = new int[n];

        for (int i = 1; i <= n; i++)
            x[i-1] = int.Parse(spl[i]);

        inp = Console.ReadLine();
        spl = inp.Split(' ');
        int m = int.Parse(spl[0]);
        int[] y = new int[m];
        for (int i = 1; i <= m; i++)
            y[i - 1] = int.Parse(spl[i]);

        inp = Console.ReadLine();
        spl = inp.Split(' ');
        int k = int.Parse(spl[0]);
        int[] z = new int[k];
        for (int i = 1; i <= k; i++)
            z[i - 1] = int.Parse(spl[i]);

        inp = Console.ReadLine();
        spl = inp.Split(' ');
        int A = int.Parse(spl[0]);
        int B = int.Parse(spl[1]);

        Array.Sort(x);
        Array.Sort(y);
        Array.Sort(z);

        double r22 = (double)x[x.Length - 1] * (double)x[x.Length - 1] / (1.0 + (double)A * (double)z[0] / (double)B / (double)y[y.Length - 1]);

        r22 = Math.Sqrt(r22);

        Console.WriteLine(r22.ToString().Replace(',', '.'));
    }
}


using System;
class Program
{
    static void Main()
    {
        string[] inputRout = Console.ReadLine().Split(' ');
        string[] inputY = Console.ReadLine().Split(' ');
        string[] inputZ = Console.ReadLine().Split(' ');
        string[] inputAB = Console.ReadLine().Split(' ');
        double A = double.Parse(inputAB[0]);
        double B = double.Parse(inputAB[1]);
        int n = int.Parse(inputRout[0]);
        int m = int.Parse(inputY[0]);
        int k = int.Parse(inputZ[0]);
        double[] Rout = new double[n];
        double[] Y = new double[m];
        double[] Z = new double[k];
        double[] Rin = new double[n * m * k];
        for (int i = 1; i < inputRout.Length; i++)
        {
            Rout[i - 1] = double.Parse(inputRout[i]);
        }
        for (int i = 1; i < inputY.Length; i++)
        {
            Y[i - 1] = double.Parse(inputY[i]);
        }
        for (int i = 1; i < inputZ.Length; i++)
        {
            Z[i - 1] = double.Parse(inputZ[i]);
        }
        for (int i = 0, y = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                for (int z = 0; z < k; z++, y++)
                {
                    Rin[y] = Math.Sqrt(Math.Pow(Rout[i], 2) * Y[j] / ((A/B)*Z[z]+Y[j]));
                }
            }
        }
        double MaxRin = Rin[0];
        for (int i = 1; i < Rin.Length; i++)
        {
            if (MaxRin < Rin[i])
            {
                MaxRin = Rin[i];
            }
        }
        Console.WriteLine(Math.Round(MaxRin,9));
    }
}


using System;
class Program
{
    static void Main()
    {
        string[] inputRout = Console.ReadLine().Split(' ');
        string[] inputY = Console.ReadLine().Split(' ');
        string[] inputZ = Console.ReadLine().Split(' ');
        string[] inputAB = Console.ReadLine().Split(' ');
        double A = double.Parse(inputAB[0]);
        double B = double.Parse(inputAB[1]);
        int n = int.Parse(inputRout[0]);
        int m = int.Parse(inputY[0]);
        int k = int.Parse(inputZ[0]);
        double[] Rout = new double[n];
        double[] Y = new double[m];
        double[] Z = new double[k];
        double[] Rin = new double[n * m * k];
        for (int i = 1; i < inputRout.Length; i++)
        {
            Rout[i - 1] = double.Parse(inputRout[i]);
        }
        for (int i = 1; i < inputY.Length; i++)
        {
            Y[i - 1] = double.Parse(inputY[i]);
        }
        for (int i = 1; i < inputZ.Length; i++)
        {
            Z[i - 1] = double.Parse(inputZ[i]);
        }
        for (int i = 0, y = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                for (int z = 0; z < k; z++, y++)
                {
                    Rin[y] = Math.Sqrt(Math.Pow(Rout[i], 2) * Y[j] / ((A/B)*Z[z]+Y[j]));
                }
            }
        }
        double MaxRin = Rin[0];
        for (int i = 1; i < Rin.Length; i++)
        {
            if (MaxRin < Rin[i])
            {
                MaxRin = Rin[i];
            }
        }
        Console.WriteLine(Math.Round(MaxRin,9).ToString().Replace(',','.'));
    }
}


using System;
class Program
{
    static void Main()
    {
        string[] inputRout = Console.ReadLine().Split(' ');
        string[] inputY = Console.ReadLine().Split(' ');
        string[] inputZ = Console.ReadLine().Split(' ');
        string[] inputAB = Console.ReadLine().Split(' ');
        double A = double.Parse(inputAB[0]);
        double B = double.Parse(inputAB[1]);
        int n = int.Parse(inputRout[0]);
        int m = int.Parse(inputY[0]);
        int k = int.Parse(inputZ[0]);
        double[] Rout = new double[n];
        double[] Y = new double[m];
        double[] Z = new double[k];
        double[] Rin = new double[m * k];
        for (int i = 1; i < inputRout.Length; i++)
        {
            Rout[i - 1] = double.Parse(inputRout[i]);
        }
        for (int i = 1; i < inputY.Length; i++)
        {
            Y[i - 1] = double.Parse(inputY[i]);
        }
        for (int i = 1; i < inputZ.Length; i++)
        {
            Z[i - 1] = double.Parse(inputZ[i]);
        }
        double MaxRout = Rout[0];
        for (int i = 1; i < Rout.Length; i++)
        {
            if (MaxRout < Rout[i])
            {
                MaxRout = Rout[i];
            }
        }
        for (int j = 0,y=0; j < m; j++)
        {
            for (int z = 0; z < k; z++, y++)
            {
                Rin[y] = Math.Sqrt(Math.Pow(MaxRout, 2) * Y[j] / ((A / B) * Z[z] + Y[j]));
            }
        }
        double MaxRin = Rin[0];
        for (int i = 1; i < Rin.Length; i++)
        {
            if (MaxRin < Rin[i])
            {
                MaxRin = Rin[i];
            }
        }
        Console.WriteLine(Math.Round(MaxRin, 9).ToString().Replace(',', '.'));
    }
}


using System;
class Program
{
    static void Main()
    {
        string[] inputRout = Console.ReadLine().Split(' ');
        string[] inputY = Console.ReadLine().Split(' ');
        string[] inputZ = Console.ReadLine().Split(' ');
        string[] inputAB = Console.ReadLine().Split(' ');
        double A = double.Parse(inputAB[0]);
        double B = double.Parse(inputAB[1]);
        int n = int.Parse(inputRout[0]);
        int m = int.Parse(inputY[0]);
        int k = int.Parse(inputZ[0]);
        double[] Rout = new double[n];
        double[] Y = new double[m];
        double[] Z = new double[k];
        for (int i = 1; i < inputRout.Length; i++)
        {
            Rout[i - 1] = double.Parse(inputRout[i]);
        }
        for (int i = 1; i < inputY.Length; i++)
        {
            Y[i - 1] = double.Parse(inputY[i]);
        }
        for (int i = 1; i < inputZ.Length; i++)
        {
            Z[i - 1] = double.Parse(inputZ[i]);
        }
        double MaxRout = Rout[0];
        for (int i = 1; i < Rout.Length; i++)
        {
            if (MaxRout < Rout[i])
            {
                MaxRout = Rout[i];
            }
        }
        double MinZ = Z[0];
        for (int i = 1; i < Z.Length; i++)
        {
            if (MinZ > Z[i])
            {
                MinZ = Z[i];
            }
        }
        double MaxY = Y[0];
        for (int i = 1; i < Y.Length; i++)
        {
            if (MaxY < Y[i])
            {
                MaxY = Y[i];
            }
        }
        double MaxRin = Math.Sqrt(Math.Pow(MaxRout, 2) * MaxY / ((A / B) * MinZ + MaxY));
        Console.WriteLine(Math.Round(MaxRin, 9).ToString().Replace(',', '.'));
    }
}