//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
//typedef long long ll;
#define int long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define clock cerr<<"\n"<<(float)clock()/CLOCKS_PER_SEC*1000<<" ms"<<endl;
#define ff first
#define ss second
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

int n,m,k,x;
vector<int> a,b,c,d,arr;

int getAns() {
    int ans=0;
    for(int i=0;i<m;i++) {
        if(arr[a[i]]>0 && arr[b[i]]>0) ans++;
    }
    return ans;
}

void getRec(int i) {
    if(i==k) {
        int y=getAns(); x= max(x,y);
        return;
    }
    arr[c[i]]++; getRec(i+1); arr[c[i]]--;
    arr[d[i]]++; getRec(i+1); arr[d[i]]--;
}

int solve() {
    x=0;
    getRec(0);
    return x;
}

signed main() {
    fastIO;
    int T=1;
//    cin>>T;
    for(int t=1;t<=T;t++) {
        cin>>n>>m;
        arr.resize(n+1,0);
        a.resize(m); b.resize(m);
        for(int i=0;i<m;i++) cin>>a[i]>>b[i];
        cin>>k;
        c.resize(k); d.resize(k);
        for(int i=0;i<k;i++) cin>>c[i]>>d[i];
        cout<<solve()<<"\n";
    }
    return 0;
}

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    #define FAST ios_base::sync_with_stdio(false);cin.tie(0);
    const double EPS = 1e-9;
    const double PI = acos(-1);
    const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
    //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
    //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
    const int dx[] = {0 , 1 , 0 , -1};
    const int dy[] = {1 , 0 , -1 , 0};
    //#define MOD         1000000007LL
    #define MAX         200015
    const ll MOD = 998244353;
    inline ll mod(ll a){return ((a % MOD + MOD) % MOD);}
    inline ll add(ll a, ll b){return mod(mod(a) + mod(b));}
    inline ll sub(ll a, ll b){return mod(mod(a) - mod(b));}

    int l[MAX],r[MAX];
    vector<int> graph[MAX];
    int depth[MAX] , vis[MAX];
    ll c[MAX];
    void depthDFS(int now , int d)
    {
        depth[now] = d;
        
        for(int a : graph[now])
        {
            if(!vis[a])
            {
                vis[a] = 1;
                depthDFS(a , d + 1);
            }
        }
    }
    
    void sumDFS(int now , ll point)
    {
        c[now] += point;
        
        for(int a : graph[now])
        {
            if(!vis[a])
            {
                vis[a] = 1;
                sumDFS(a , c[now]);
            }
        }
            
    }
    
    
    int main()
    {
        FAST
        int t;
        t = 1;

        while(t--)
        {
            int n;
            cin >> n;
            
            
            for(int i = 1 ; i < n ; i++)
            {
                int a , b;
                cin >> a >> b;
                a-- , b--;
                
                l[i] = a , r[i] = b;
                graph[a].push_back(b);
                graph[b].push_back(a);
            }
            
            vis[0] = 1;
            depthDFS(0 , 0);
            
            int q;
            cin >> q;
            
            for(int i = 0 ; i < q ; i++)
            {
                int t , e , x;
                cin >> t >> e >> x;
                
                int yes = l[e], no = r[e];
                if(t == 2)
                {
                    swap(yes , no);
                }
                
                if(depth[yes] < depth[no])
                {
                    c[0] += x;
                    c[no] -= x;
                }
                else c[yes] += x;
            }
            
            memset(vis , 0 , sizeof(vis));
            vis[0] = 1;
            sumDFS(0 , 0);
            
            for(int i = 0 ; i < n ; i++)cout << c[i] << endl;
            
            
        }
    }


