#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

#define MAXN 100100

int n,m;
int cnt[MAXN],res[MAXN],bleg[MAXN];

vector < pair<int,int> > edge[MAXN];
vector <int> Q[MAXN];

int Find(int x)
{
    return bleg[x]=(bleg[x]==x?x:Find(bleg[x]));
}

void dfs(int u)
{
    int i,v;
    cnt[u]=0;
    bleg[u]=u;
    for(i=0;i<Q[u].size();i++)
    {
        cnt[u]++;
        v=Q[u][i];
        if(bleg[v])
        {
            cnt[Find(v)]-=2;
        }
    }
    for(i=0;i<edge[u].size();i++)
    {
        v=edge[u][i].first;
        if(bleg[v]) continue;
        dfs(v);
        cnt[u]+=cnt[v];
        res[edge[u][i].second]=cnt[v];
        bleg[Find(v)]=bleg[u];
    }
}

int main()
{
    int i,u,v;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(make_pair(v,i));
        edge[v].push_back(make_pair(u,i));
    }
    cin>>m;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&u,&v);
        Q[u].push_back(v);
        Q[v].push_back(u);
    }
    dfs(1);
    for(i=0;i<n-2;i++) printf("%d ",res[i]);
    printf("%d\n",res[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

#define MAXN 100100

int n,m;
int cnt[MAXN],res[MAXN],bleg[MAXN];

vector < pair<int,int> > edge[MAXN];
vector <int> Q[MAXN];

int Find(int x)
{
    return bleg[x]=(bleg[x]==x?x:Find(bleg[x]));
}

void dfs(int u)
{
    int i,v;
//  cnt[u]=0;
    bleg[u]=u;
    for(i=0;i<Q[u].size();i++)
    {
        cnt[u]++;
        v=Q[u][i];
        if(bleg[v])
        {
            cnt[Find(v)]-=2;
        }
    }
    for(i=0;i<edge[u].size();i++)
    {
        v=edge[u][i].first;
        if(bleg[v]) continue;
        dfs(v);
        cnt[u]+=cnt[v];
        res[edge[u][i].second]=cnt[v];
        bleg[v]=u;
    }
}

int main()
{
    int i,u,v;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(make_pair(v,i));
        edge[v].push_back(make_pair(u,i));
    }
    cin>>m;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&u,&v);
        Q[u].push_back(v);
        Q[v].push_back(u);
    }
    dfs(1);
    for(i=0;i<n-2;i++) printf("%d ",res[i]);
    printf("%d\n",res[i]);
    return 0;
}


#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;

#define MAXN 100100

int n,m;
int cnt[MAXN],res[MAXN],bleg[MAXN];

vector < pair<int,int> > edge[MAXN];
vector <int> Q[MAXN];

int Find(int x)
{
    return bleg[x]=(bleg[x]==x?x:Find(bleg[x]));
}

void dfs(int u)
{
    int i,v;
    cnt[u]=0;
    bleg[u]=u;
    for(i=0;i<Q[u].size();i++)
    {
        cnt[u]++;
        v=Q[u][i];
        if(bleg[v])
        {
            cnt[Find(v)]-=2;
        }
    }
    for(i=0;i<edge[u].size();i++)
    {
        v=edge[u][i].first;
        if(bleg[v]) continue;
        dfs(v);
        cnt[u]+=cnt[v];
        res[edge[u][i].second]=cnt[v];
        bleg[v]=u;
    }
}

int main()
{
    int i,u,v;
    cin>>n;
    for(i=0;i<n-1;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(make_pair(v,i));
        edge[v].push_back(make_pair(u,i));
    }
    cin>>m;
    for(i=0;i<m;i++)
    {
        scanf("%d%d",&u,&v);
        Q[u].push_back(v);
        Q[v].push_back(u);
        if(u==v) while(1);
    }
    dfs(1);
    for(i=0;i<n-2;i++) printf("%d ",res[i]);
    printf("%d\n",res[i]);
    return 0;
}
/*
7
1 2
1 3
2 4
2 5
3 6
3 7

4
6 3
6 1
6 5
1 1
*/


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
vi bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[MAXN][20], vv[MAXN], f[MAXN];

int hmin(int x, int y){return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int main(int argc, char **argv){
    scanf("%d", &N);
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    vii heavy;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy.pb(mp(x, y)); }
    }
    sort(ALL(heavy));
    FOR(i, 0, heavy.size()){
        int x = heavy[i].x, y = heavy[i].y;
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x > y) swap(x, y);
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 200010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
//vi bit[MAXN];
int* bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[MAXN][20], vv[MAXN], f[MAXN];

inline int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

inline void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

inline int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

inline void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

inline int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int heavy[MAXN][2];

int main(int argc, char **argv){
    scanf("%d", &N);
    memset(par, -1, sizeof(par));
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    int ptr = 0;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy[ptr][0] = x, heavy[ptr][1] = y; ptr++; }
    }
    FOR(i, 0, ptr){
        int x = heavy[i][0], y = heavy[i][1];
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    //FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    FOR(i, 1, bit_num+1){
        bit[i] = new int[bit_size[i]+10];
        FOR(j, 0, bit_size[i]+2) bit[i][j] = 0;
    }
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x == y) continue;
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 200010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
int A[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
//vi bit[MAXN];
int* bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[MAXN][20], vv[MAXN], f[MAXN];

inline int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

inline void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

inline int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

inline void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

inline int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int heavy[MAXN][2];

int main(int argc, char **argv){
    scanf("%d", &N);
    memset(par, -1, sizeof(par));
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    int ptr = 0;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy[ptr][0] = x, heavy[ptr][1] = y; ptr++; }
    }
    FOR(i, 0, ptr){
        int x = heavy[i][0], y = heavy[i][1];
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    //FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    FOR(i, 1, bit_num+1){
        bit[i] = new int[bit_size[i]+10];
        FOR(j, 0, bit_size[i]+2) bit[i][j] = 0;
    }
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x == y) continue;
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            A[u] += v;
            //printf("Update 1~%d (%d)\n", u+1, v);
            //puts("");
        }
    }
    FOR(i, 1, N+1){
        int u = i, v = A[i];
        while (u != -1){
            //printf("Currently At %d\n", u+1);
            if (bit_id[u] == 0){
                val[u] += v;
            }else{
                add(bit_id[u], bit_pos[u], v);
                u = skip[bit_id[u]];
            }
            u = par[u];
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
//vi bit[MAXN];
int* bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[210000][20], vv[MAXN], f[MAXN];

int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int main(int argc, char **argv){
    scanf("%d", &N);
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    vii heavy;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy.pb(mp(x, y)); }
    }
    sort(ALL(heavy));
    FOR(i, 0, heavy.size()){
        int x = heavy[i].x, y = heavy[i].y;
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    //FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    FOR(i, 1, bit_num+1){
        bit[i] = new int[bit_size[i]+10];
        FOR(j, 0, bit_size[i]+2) bit[i][j] = 0;
    }
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x == y) continue;
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d\n", val[y]);
        else printf("%d\n", sum(bit_id[y], bit_pos[y]));
    }
    //puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
vi bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[2*MAXN+10][20], vv[MAXN], f[MAXN];

int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int main(int argc, char **argv){
    scanf("%d", &N);
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    vii heavy;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy.pb(mp(x, y)); }
    }
    sort(ALL(heavy));
    FOR(i, 0, heavy.size()){
        int x = heavy[i].x, y = heavy[i].y;
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x == y) continue;
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 200010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int d[MAXN], t, val[MAXN], A[MAXN];
int ST[MAXN][20], vv[MAXN], f[MAXN];

inline int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

inline void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

inline int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int getres(int u, int p){
    int k = 0;
    FOR(i, 0, adj[u].size()) if (adj[u][i] != p)
        k += getres(adj[u][i], u);
    val[u] += k + A[u];
    return k + A[u];
}

int main(int argc, char **argv){
    scanf("%d", &N);
    memset(par, -1, sizeof(par));
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        if (x == y) continue;
        int p = lca(x, y);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            A[u] += v;
        }
    }
    getres(1, -1);
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        printf("%d ", val[y]);
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
vi bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[MAXN][20], vv[MAXN], f[MAXN];

int hmin(int x, int y){return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int main(int argc, char **argv){
    scanf("%d", &N);
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    vii heavy;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy.pb(mp(x, y)); }
    }
    sort(ALL(heavy));
    FOR(i, 0, heavy.size()){
        int x = heavy[i].x, y = heavy[i].y;
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_id[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x > y) swap(x, y);
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
//vi bit[MAXN];
int* bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[210000][20], vv[MAXN], f[MAXN];

inline int hmin(int x, int y){ return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    vv[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), vv[++t] = x;
}

inline void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = vv[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

inline int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

inline void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

inline int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int heavy[MAXN][2];

int main(int argc, char **argv){
    scanf("%d", &N);
    memset(par, -1, sizeof(par));
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        //if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(1, -1);
    //getsz(1, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    FOR(i, 0, N-1) SZ[E[i][0]]++;
    FOR(i, 0, N-1) SZ[i]++;
    int ptr = 0;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy[ptr][0] = x, heavy[ptr][1] = y; ptr++; }
    }
    FOR(i, 0, ptr){
        int x = heavy[i][0], y = heavy[i][1];
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_pos[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    //FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    FOR(i, 1, bit_num+1){
        bit[i] = new int[bit_size[i]+10];
        FOR(j, 0, bit_size[i]+2) bit[i][j] = 0;
    }
    t = 0;
    dfs2(1, 0, 1);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        //--x, --y;
        if (x == y) continue;
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#define eps 1e-9
#define FOR(x, s, e) for(int x = (s); x < (e); ++x)
#define FORc(x, s, e, c) for(int x = (s); x < (e) && (c); ++x)
#define STEP(x, s, e, d) for(int x = (s); x < (e); x+=(d))
#define ROF(x, s, e) for(int x = (s); x >= (e); --x)
#define ROFc(x, s, e, c) for(int x = (s); x >= (e) && (c); --x)
#define vb vector<bool>
#define vi vector<int>
#define vii vector<pair<int, int> >
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define ALL(X) X.begin(), X.end()
#define LL long long
#define pii pair<int, int>
#define x first
#define y second
#define gcd(x, y) __gcd((x), (y))
#define countbit(x) __builtin_popcount(x)
#define MAXN 100010

using namespace std;

int N, bit_num;
int SZ[MAXN], E[MAXN][2], par[MAXN], skip[MAXN];
vi adj[MAXN];
int bit_id[MAXN], bit_pos[MAXN], bit_size[MAXN];
vi bit[MAXN];
int d[MAXN], t, val[MAXN];
int ST[MAXN][20], v[MAXN], f[MAXN];

int hmin(int x, int y){return d[x] < d[y] ? x : y;}

void dfs2(int x, int y, int p){
    d[x] = y;
    v[++t] = x;
    f[x] = t;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            dfs2(adj[x][i], y+1, x), v[++t] = x;
}

void pre(){
    for (int i=1; i<=t; i++) ST[i][0] = v[i];
    for (int j=1; (1<<j)<=t; j++)
        for (int i=1; i+(1<<j)-1<=t; i++)
            ST[i][j] = hmin(ST[i][j-1], ST[i+(1<<(j-1))][j-1]);
}

int lca(int x, int y){
    int tt;
    x = f[x];
    y = f[y];
    if (x > y) swap(x, y);
    for (tt=0; (1<<(tt+1))<=(y-x+1); tt++);
    return hmin(ST[x][tt], ST[y-(1<<tt)+1][tt]);
}

int getsz(int v, int p){
    FOR(i, 0, adj[v].size()) if (adj[v][i] != p)
        SZ[v] += getsz(adj[v][i], v);
    SZ[v]++;
    return SZ[v];
}

void add(int k, int pos, int value){
    for (int i=pos;i;i-=i&-i) bit[k][i]+=value;
}

int sum(int k, int pos){
    int cnt=0;
    for (int i=pos;i<=bit_size[k];i+=i&-i) cnt += bit[k][i];
    return cnt;
}

void getpar(int x, int p){
    par[x] = p;
    FOR(i, 0, adj[x].size())
        if (adj[x][i] != p)
            getpar(adj[x][i], x);
}

int main(int argc, char **argv){
    scanf("%d", &N);
    FOR(i, 0, N-1){
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        if (x > y) swap(x, y);
        E[i][0] = x, E[i][1] = y;
        adj[x].pb(y);
        adj[y].pb(x);
    }
    getpar(0, -1);
    getsz(0, -1);
    FOR(i, 0, N-1) if (par[E[i][0]] == E[i][1]) swap(E[i][0], E[i][1]);
    vii heavy;
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        if (SZ[y] * 2 >= SZ[x]){ heavy.pb(mp(x, y)); }
    }
    sort(ALL(heavy));
    FOR(i, 0, heavy.size()){
        int x = heavy[i].x, y = heavy[i].y;
        //printf("Heavy edge %d %d\n", x+1, y+1);
        if (bit_id[x] == 0){
            bit_id[x] = ++bit_num;
            bit_pos[x] = 1;
            bit_size[bit_id[x]]++;
            skip[bit_num] = x;
        }
        bit_id[y] = bit_id[x];
        bit_pos[y] = bit_id[x] + 1;
        bit_size[bit_id[x]]++;
    }
    //printf("Num of bit = %d\n", bit_num);
    FOR(i, 1, bit_num+1) bit[i] = vi(bit_size[i]+10, 0);
    t = 0;
    dfs2(0, 0, 0);
    pre();
    int K;
    scanf("%d", &K);
    FOR(tt, 0, K){
        int x, y;
        scanf("%d%d", &x, &y);
        --x, --y;
        if (x > y) swap(x, y);
        int p = lca(x, y);
        //printf("%d ~ %d meets at %d\n", x+1, y+1, p+1);
        int itr[3] = {x, y, p};
        int updv[3] = {1, 1, -2};
        FOR(k, 0, 3){
            int u = itr[k], v = updv[k];
            //printf("Update 1~%d (%d)\n", u+1, v);
            while (u != -1){
                //printf("Currently At %d\n", u+1);
                if (bit_id[u] == 0){
                    val[u] += v;
                }else{
                    add(bit_id[u], bit_pos[u], v);
                    u = skip[bit_id[u]];
                }
                u = par[u];
            }
            //puts("");
        }
    }
    FOR(i, 0, N-1){
        int x = E[i][0], y = E[i][1];
        //printf("%d - %d: ", x+1, y+1);
        if (bit_id[y] == 0) printf("%d ", val[y]);
        else printf("%d ", sum(bit_id[y], bit_pos[y]));
    }
    puts("");
	return 0;
}


#include<string.h>
#include<stdio.h>
#include<vector>
#include<math.h>
using namespace std;
const int M =100100;
const double inf = 1e20;
int min(int a,int b){return a<b?a:b;}
int n,k,tdfn,tot;
int dp[20][2*M],vis[M];
int B[2*M],LOG[2*M],used[M],F[2*M],pos[M],c[M],la[M];
vector<int> edge[M],eg[M];
int ans[M];
void rmq_init(int n,int num[])
{
	int i,j;
	for(j=1;j<=n;j++)
		dp[0][j]=num[j];
	for(j=1;j<=LOG[n];j++)
	{
		int limit=n+1-(1<<j);
		for(i=1;i<=limit;i++)
		{
			int x=i+(1<<j>>1);
			dp[j][i]=min(dp[j-1][x],dp[j-1][i]);
		}
	}
}
int rmq(int l,int r,int num[])
{
	int m=LOG[r-l+1];
	return min(dp[m][l],dp[m][r-(1<<m)+1]);
}
void dfs(int s)
{
	int i,t;
	used[s]=1;
	int tmp=++tdfn;
	B[++tot]=tmp;F[tmp]=s;
	pos[s]=tot;
	int sz=edge[s].size();
	for(i=0;i<sz;i++)
	{
		t=edge[s][i];
		if(used[t])  continue;
		dfs(t);
		B[++tot]=tmp;//backtrack
	}
	used[s]=0;
}
int lca(int a,int b)
{
	if(pos[a]>pos[b]) swap(a,b);
	int ans=rmq(pos[a],pos[b],B);
	return F[ans];
}
void init()
{
	tdfn=0; tot=0;
	memset(used,0,sizeof(used));
	dfs(1);
	rmq_init(tot,B);
}
int solve(int u,int edge_num)
{
	int sum=0;
	used[u]=1;
	int sz=edge[u].size();
	for(int i=0;i<sz;i++)
	{
		int to=edge[u][i];
		if(used[to]) continue;
		sum+=solve(to,eg[u][i]);
	}
	sum-=la[u];
	if(edge_num) ans[edge_num]=sum+c[u];
	return ans[edge_num];
}
int main()
{
	int i,n,m,a,b,w;
	LOG[0]=-1;
	for(i=1;i<2*M;i++)  LOG[i]=LOG[i>>1]+1;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<=n;i++){ edge[i].clear();c[i]=0;}
		char str[5];
		for(i=1;i<n;i++)
		{
			scanf("%d%d",&a,&b);
			edge[a].push_back(b);
			edge[b].push_back(a);
			eg[a].push_back(i);
			eg[b].push_back(i);
		}
		init();
		scanf("%d",&k);
		while(k--)
		{
			scanf("%d%d",&a,&b);
			c[a]++;
			c[b]++;
			int x=lca(a,b);
			la[x]+=2;
		//	printf("x=%d\n",x);
		}
		solve(1,0);
		for(i=1;i<n;i++) printf("%d ",ans[i]);
		puts("");
	}
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<string>
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<time.h>
#include<queue>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define lowbit(x) ((x)&(-(x)))
#define sqr(x) ((x)*(x))
#define PB push_back
#define MP make_pair
//typedef long long lld;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
const int maxn  =  100010;
VI edge[maxn],ee[maxn],EE[maxn];
int L[maxn],R[maxn],up[maxn],down[maxn];
int tot;
int p[maxn][17];
int dep[maxn];
void dfs(int u,int f,int edge_num)
{
	dep[u]=dep[f]+1;
	up[u]=edge_num;
	L[edge_num] = ++tot;
	for(int i=0;i<edge[u].size();i++)
	{
		int v=edge[u][i];
		if(v==f) continue;
		p[v][0]=u;
		for(int j=1;j<17;j++) p[v][j]=p[p[v][j-1]][j-1];
		EE[u].push_back(ee[u][i]);
		dfs(v,u,ee[u][i]);
	}
	R[edge_num] = ++tot;
}
int LCA(int a,int b)
{
	if(dep[a] > dep[b]) swap(a,b);
    if(dep[a] < dep[b])  {
        int del=dep[b]-dep[a];
        for(int i=0;i<17;i++) if(del&(1<<i)) b=p[b][i];
    }
    if(a != b) {
        for(int i=17-1;i>=0;i--)
            if(p[a][i]!=p[b][i])
                a=p[a][i],b=p[b][i];
            a=p[a][0],b=p[b][0];
    }
    return a;
}
int sum[200010<<2],add[200010<<2];
inline void pushup(int rt)
{
	sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
inline void pushdown(int rt,int l,int r)
{
	int m=l+r>>1;
	if(add[rt])
	{
		add[rt<<1] += add[rt];
		add[rt<<1|1] += add[rt];
		sum[rt<<1] += add[rt]*(m-l+1);
		sum[rt<<1|1] += add[rt]*(r-m);
		add[rt]=0;
	}
}
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
void update(int L,int R,int val,int l,int r,int rt)
{
	if(L <= l && r <= R)
	{
		sum[rt]+=val*(r-l+1);
		add[rt]+=val;
		return ;
	}
	pushdown(rt,l,r);
	int m=l+r>>1;
	if(L <= m) update(L,R,val,lson);
	if(R > m) update(L,R,val,rson);
	pushup(rt);
}
int query(int p,int l,int r,int rt)
{
	if(l==r) return sum[rt];
	pushdown(rt,l,r);
	int m=l+r>>1;
    if(p<=m) return query(p,lson);
	return query(p,rson);
}
int ans[200010];
int main()
{
	int n,u,v,i,j,m;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d%d",&u,&v);
		edge[u].push_back(v);
		edge[v].push_back(u);
		ee[u].push_back(i);
		ee[v].push_back(i);
	}
	dfs(1,0,0);
	scanf("%d",&m);
	for(i=1;i<=m;i++)
	{
		scanf("%d%d",&u,&v);
		if(u==v) continue;
        int lca=LCA(u,v);
        if(lca!=u && lca!=v){
      //  	printf("lca=%d %d\n",lca,*ee[lca].begin());
	//		printf("%d %d %d\n",L[*ee[lca].begin()],L[up[u]],L[up[v]]);
			update(L[*EE[lca].begin()],L[up[u]],1,1,tot,1);
			update(L[*EE[lca].begin()],L[up[v]],1,1,tot,1);
		} else if(lca==u) {
	//		printf("hf %d %d\n",L[*EE[lca].begin()],L[up[v]]);
			update(L[*EE[lca].begin()],L[up[v]],1,1,tot,1);
		}  else {
	//		printf("sss  %d %d\n",L[*EE[lca].begin()],L[up[u]]);
			update(L[*EE[lca].begin()],L[up[u]],1,1,tot,1);
		}
	}
	for(i=1;i<=tot;i++)  ans[i]=query(i,1,tot,1);
	for(i=1;i<n;i++)
	{
		printf("%d ",ans[L[i]]-ans[R[i]]);
	}
	return 0;
}
/*
7
1 2
1 3
2 4
2 5
3 6
3 7
4
2 1
1 2
1 6
4 5
*/


/*
树链剖分，输入边权，p个操作，
给u，v间的简单路径的边权都加上1
最后输出所有边的边权
*/
#include<cstdio>
#include<cstring>
#include<stack>
#include<algorithm>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
const int maxn = 200010;
const int inf = ~0u>>2;
int M[maxn<<2];
int add[maxn<<2];
struct node{
    int s,t,w,next;
}edge[maxn*2];
int E,n;
int size[maxn] , fa[maxn] , heavy[maxn] , head[maxn] , vis[maxn];
int dep[maxn] , rev[maxn] , num[maxn] ;
int Seg_size;
int find(int x){return x==fa[x]?x:fa[x]=find(fa[x]);}
void add_edge(int s,int t,int w)
{
    edge[E].w=w;
    edge[E].s=s;
    edge[E].t=t;
    edge[E].next=head[s];
    head[s]=E++;
}
void dfs(int u,int f)
{
    int mx=-1,e=-1;
    size[u]=1;
    for(int i=head[u];i!=-1;i=edge[i].next)
    {
        int v=edge[i].t;
        if(v==f) continue;
        dep[v]=dep[u]+1;
        rev[v]=i^1;
        dfs(v,u);
        size[u]+=size[v];
        if(size[v]>mx)
        {
            mx=size[v];
            e=i;
        }
    }
    heavy[u]=e;
    if(e!=-1)  fa[edge[e].t]=u;
}
inline void pushup(int rt){
    M[rt]=M[rt<<1]+M[rt<<1|1];
}
void pushdown(int rt,int m){
    if(add[rt]){
        add[rt<<1]+=add[rt];
        add[rt<<1|1]+=add[rt];
        M[rt<<1]+=add[rt]*(m-(m>>1));
        M[rt<<1|1]+=add[rt]*(m>>1);
        add[rt]=0;
    }
}
void build(int l,int r,int rt){
    M[rt]=add[rt]=0;
    if(l==r){
        return ;
    }
    int m=(l+r)>>1;
    build(lson);
    build(rson);
}
void update(int L,int R,int val,int l,int r,int rt){
    if(L<=l&&r<=R){
        M[rt]+=val;
        add[rt]+=val;
        return ;
    }
    pushdown(rt,r-l+1);
    int m=(l+r)>>1;
    if(L<=m) update(L,R,val,lson);
    if(R>m) update(L,R,val,rson);
    pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
    if(L<=l&&r<=R){
        return M[rt];
    }
    pushdown(rt,r-l+1);
    int m=(l+r)>>1;
    int ret=0;
    if(L<=m) ret+=query(L,R,lson);
    if(R>m) ret+=query(L,R,rson);
    return ret;
}
void prepare()
{
    int i;
    build(1,n,1);
    memset(num,-1,sizeof(num));
    dep[0]=0;Seg_size=0;
    for(i=0;i<n;i++) fa[i]=i;
    dfs(0,0);
    for(i=0;i<n;i++)
    {
        if(heavy[i]==-1)
        {
            int pos=i;
            while(pos && edge[heavy[edge[rev[pos]].t]].t == pos)
            {
                int t=rev[pos];
                num[t]=num[t^1]=++Seg_size;//printf("pos=%d  val=%d t=%d\n",Seg_size,edge[t].w,t);
                update(Seg_size,Seg_size,edge[t].w,1,n,1);
                pos=edge[t].t;
            }
        }
    }
}
int lca(int u,int v)
{
    while(1)
    {
        int a=find(u),b=find(v);
        if(a==b) return dep[u] < dep[v] ? u : v;//a,b在同一条重链上
        else if(dep[a]>=dep[b]) u=edge[rev[a]].t;
        else v=edge[rev[b]].t;
    }
}
void CH(int u,int lca,int val)
{
    while(u!=lca)
    {
        int r=rev[u];
        if(num[r]==-1) edge[r^1].w+=val,edge[r].w+=val,u=edge[r].t;
        else
        {
            int p=fa[u];
            if(dep[p] < dep[lca]) p=lca;
            int l=num[r];
            r=num[heavy[p]];
            update(l,r,val,1,n,1);
            u=p;
        }
    }
}
void change(int u,int v,int val)
{
    int p=lca(u,v);
    CH(u,p,val);
    CH(v,p,val);
}
int solve(int id)
{
	int r=id;
	if(num[r]==-1) return edge[r].w;
	else return query(num[r],num[r],1,n,1);
}
int main()
{
    int t,i,a,b,c,m,ca=1,p;
    while(scanf("%d",&n)!=EOF)
    {
        memset(head,-1,sizeof(head));
        E=0;
        for(i=0;i<n-1;i++)
        {
            scanf("%d%d",&a,&b);a--;b--;
            add_edge(a,b,0);
            add_edge(b,a,0);
        }
        prepare();
		scanf("%d",&p);
        while(p--)
        {
            scanf("%d%d",&a,&b);a--;b--;
            change(a,b,1);
        }
		for(i=0;i<n-1;i++)
		{
			if(i!=0) printf(" ");
			printf("%d",solve(2*i));
		}
		puts("");
    }
    return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<string>
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<time.h>
#include<queue>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn  =  100010;
#define lowbit(x) ((x)&(-(x)))
#define sqr(x) ((x)*(x))
#define PB push_back
#define MP make_pair
typedef unsigned long long ULL;
typedef long long lld;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
const int POW = 17;
int p[maxn][POW];
VI edge[maxn],ee[maxn];
int cnt[maxn];
int dep[maxn];
void dfs(int u,int f)
{
    dep[u]=dep[f]+1;
    for(int i=0;i<edge[u].size();i++)
    {
        int v=edge[u][i];
        if(v==f) continue;
        p[v][0]=u;
        for(int i=1;i<POW;i++) p[u][i]=p[p[u][i-1]][i-1];
        dfs(v,u);
    }
}
int LCA(int a,int b)
{
    if(dep[a] > dep[b]) swap(dep[a],dep[b]);
    if(dep[a] < dep[b])  {
        int del=dep[b]-dep[a];
        for(int i=0;i<POW;i++) if(del&(1<<i)) b=p[b][i];
    }
    if(a != b) {
        for(int i=POW-1;i>=0;i--)
            if(p[a][i]!=p[b][i])
                a=p[a][i],b=p[b][i];
            a=p[a][0],b=p[b][0];
    }
    return a;
}
int ans[maxn];
int la[maxn];
bool vis[maxn];
int solve(int u,int edge_num)
{
    vis[u]=true;
    int sum=0;
    for(int i=0;i<edge[u].size();i++)
    {
          int v=edge[u][i];
          if(vis[v]) continue;
          sum+=solve(v,ee[u][i]);
    }
    sum-=la[u];
    if(edge_num) ans[edge_num]=sum+cnt[u];
    return ans[edge_num];
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(v);
        edge[v].push_back(u);
        ee[u].push_back(i);
        ee[v].push_back(i);
    }int m;
    dfs(1,0);
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        cnt[u]++;cnt[v]++;
        la[LCA(u,v)]+=2;
    }
    solve(1,0);
    for(int i=1;i<n;i++) printf("%d ",ans[i]);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<string>
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<time.h>
#include<queue>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define lowbit(x) ((x)&(-(x)))
#define sqr(x) ((x)*(x))
#define PB push_back
#define MP make_pair
//typedef long long lld;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
const int maxn  =  100010;
VI edge[maxn],ee[maxn];
int L[maxn],R[maxn],up[maxn],down[maxn];
bool vis[maxn];
int tot;
int p[maxn][17];
int dep[maxn];
void dfs(int u,int f,int edge_num)
{
    dep[u]=dep[f]+1;
    vis[u]=true;
    up[u]=edge_num;
    L[edge_num] = ++tot;
    for(int i=0;i<edge[u].size();i++)
    {
        int v=edge[u][i];
        if(vis[v]) continue;
        p[v][0]=u;
        for(int j=1;j<17;j++) p[v][j]=p[p[v][j-1]][j-1];
        dfs(v,u,ee[u][i]);
    }
    R[edge_num] = ++tot;
}
int LCA(int a,int b)
{
    if(dep[a] > dep[b]) swap(a,b);
    if(dep[a] < dep[b])  {
        int del=dep[b]-dep[a];
        for(int i=0;i<17;i++) if(del&(1<<i)) b=p[b][i];
    }
    if(a != b) {
        for(int i=17-1;i>=0;i--)
            if(p[a][i]!=p[b][i])
                a=p[a][i],b=p[b][i];
            a=p[a][0],b=p[b][0];
    }
    return a;
}
int sum[200010<<2],add[200010<<2];
inline void pushup(int rt)
{
    sum[rt] = sum[rt<<1] + sum[rt<<1|1];
}
inline void pushdown(int rt,int l,int r)
{
    int m=l+r>>1;
    if(add[rt])
    {
        add[rt<<1] += add[rt];
        add[rt<<1|1] += add[rt];
        sum[rt<<1] += add[rt]*(m-l+1);
        sum[rt<<1|1] += add[rt]*(r-m);
        add[rt]=0;
    }
}
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
void update(int L,int R,int val,int l,int r,int rt)
{
    if(L <= l && r <= R)
    {
        sum[rt]+=val*(r-l+1);
        add[rt]+=val;
        return ;
    }
    pushdown(rt,l,r);
    int m=l+r>>1;
    if(L <= m) update(L,R,val,lson);
    if(R > m) update(L,R,val,rson);
    pushup(rt);
}
int query(int p,int l,int r,int rt)
{
    if(l==r) return sum[rt];
    pushdown(rt,l,r);
    int m=l+r>>1;
    if(p<=m) return query(p,lson);
    return query(p,rson);
}
int ans[200010];
int main()
{
    int n,u,v,i,j,m;
    scanf("%d",&n);
    for(i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(v);
        edge[v].push_back(u);
        ee[u].push_back(i);
        ee[v].push_back(i);
    }
    dfs(1,0,0);
    scanf("%d",&m);
    for(i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        if(u==v) continue;
        int lca=LCA(u,v);
        if(lca!=u && lca!=v){
            update(L[*ee[lca].begin()],L[up[u]],1,1,tot,1);
            update(L[*ee[lca].begin()],L[up[v]],1,1,tot,1);
        } else if(lca==u) {
            update(L[*ee[lca].begin()],L[up[v]],1,1,tot,1);
        }  else {
            update(L[*ee[lca].begin()],L[up[u]],1,1,tot,1);
        }
    }
    for(i=1;i<=tot;i++)  ans[i]=query(i,1,tot,1);
    for(i=1;i<n;i++)
    {
        printf("%d ",ans[L[i]]-ans[R[i]]);
    }
    return 0;
}


#include <cstdio>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int tree[10000000], ord[10000000], h[100000], n, k = 0, st[100000], a[100000], end[100000];
bool alr[100000];
vector< int > e[100000], e_num[100000];
int res[100000], q;
int  min(int a,int b){
	return a<b?a:b;
}
int max(int a,int b){
	return a>b?a:b;
}
void dfs_c(int v, int curh) {
	ord[k++] = v;
	h[v] = curh;
	alr[v] = true;
	st[v] = k - 1;
	for (int i = 0; i < e[v].size(); i++) {
		if (!alr[e[v][i]]) {
			dfs_c(e[v][i], curh + 1);
			ord[k++] = v;
		}
	}
	alr[v] = false;
}
void construct(int v, int l, int r) {
	if (l == r) {
		tree[v] = ord[l];
		return;
	}
	int med = (l + r) / 2;
	construct(v * 2 + 1, l , med);
	construct(v * 2 + 2, med + 1, r);
	tree[v] = h[tree[v * 2 + 1]] < h[tree[v * 2 + 2]] ? tree[v * 2 + 1] : tree[v * 2 + 2];
}
int dfs(int v, int num) {
	int tsum = 0;
	alr[v] = true;
	for (int i = 0; i < e[v].size(); i++)
	{
		if (!alr[e[v][i]])

		{
		//	int to=e[v][i];
		//	printf("to=%d\n",to);
		//	printf("makr\n");
			tsum += dfs(e[v][i], e_num[v][i]);
		}
	}
	tsum -= end[v];
	if (num != -1)
		res[num] = tsum + a[v];
	else return 0;
	return res[num];
}
int min_v(int v, int l, int r, int la, int ra) {
	if (l == la && r == ra)
		return tree[v];
	int med = (l + r) / 2;
	if (ra <= med)
		return min_v(v * 2 + 1, l, med, la, ra);
	if (la > med)
		return min_v(v * 2 + 2, med + 1, r, la, ra);
	int temp1 = min_v(v * 2 + 1, l, med, la, med), temp2 = min_v(v * 2 + 2, med + 1, r, med + 1, ra);
	return h[temp1] < h[temp2] ? temp1 : temp2;
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n - 1; i++) {
		int v1, v2;
		scanf("%d%d", &v1, &v2); v1--; v2--;
		e[v1].push_back(v2); e[v2].push_back(v1);
		e_num[v1].push_back(i); e_num[v2].push_back(i);
	}
	dfs_c(0, 0); k--;
//	printf("k=%d\n",k);
//	for(int i=0;i<=k;i++) printf("%d ",ord[i]+1);puts("");
	construct(0, 0, k);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		int v1, v2;
		scanf("%d%d", &v1, &v2); v1--; v2--;
		int lca = min_v(0, 0, k, min(st[v1], st[v2]), max(st[v1], st[v2]));
		a[v1]++; a[v2]++; end[lca] += 2;
	}
	dfs(0, -1);
	for (int i = 0; i < n - 1; i++)
		printf("%d ", res[i]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<set>
#include<string>
#include<iostream>
#include<cmath>
#include<vector>
#include<map>
#include<stack>
#include<time.h>
#include<queue>
#include<cstdlib>
#include<algorithm>
using namespace std;
const int maxn  =  100010;
#define lowbit(x) ((x)&(-(x)))
#define sqr(x) ((x)*(x))
#define PB push_back
#define MP make_pair
typedef unsigned long long ULL;
typedef long long lld;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int,int> PII;
const int POW = 17;
int p[maxn][POW];
VI edge[maxn],ee[maxn];
int cnt[maxn];
int d[maxn];
void dfs(int u,int fa){
    d[u]=d[fa]+1;
    p[u][0]=fa;
    for(int i=1;i<POW;i++) p[u][i]=p[p[u][i-1]][i-1];
    int sz=edge[u].size();
    for(int i=0;i<sz;i++){
        int v=edge[u][i];
        if(v==fa) continue;
        dfs(v,u);
    }
}
int LCA( int a, int b ){
    if( d[a] > d[b] ) a ^= b, b ^= a, a ^= b;
    if( d[a] < d[b] ){
        int del = d[b] - d[a];
        for( int i = 0; i < POW; i++ ) if(del&(1<<i)) b=p[b][i];
    }
    if( a != b ){
        for( int i = POW-1; i >= 0; i-- )
            if( p[a][i] != p[b][i] )
                 a = p[a][i] , b = p[b][i];
        a = p[a][0], b = p[b][0];
    }
    return a;
}
int ans[maxn];
int la[maxn];
bool vis[maxn];
int solve(int u,int edge_num)
{
    vis[u]=true;
    int sum=0;
    for(int i=0;i<edge[u].size();i++)
    {
          int v=edge[u][i];
          if(vis[v]) continue;
          sum+=solve(v,ee[u][i]);
    }
    sum-=la[u];
    if(edge_num) ans[edge_num]=sum+cnt[u];
    return ans[edge_num];
}
int main()
{
    int n,u,v;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        edge[u].push_back(v);
        edge[v].push_back(u);
        ee[u].push_back(i);
        ee[v].push_back(i);
    }int m;
    dfs(1,0);
    scanf("%d",&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        cnt[u]++;cnt[v]++;
        la[LCA(u,v)]+=2;
    }
    solve(1,0);
    for(int i=1;i<n;i++) printf("%d ",ans[i]);
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      if(n < 10000)
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);
    for(int i = 0; i < n; i++)
    {
      int p;
      // read p, the parent of node i or -1 if node i is the root
      if(parent[i] == -2)
        p = -1;
      else
        p = parent[i];
      A[i][0] = p;
      if(p != -1)
          g[p].push_back(i);
      else
          root = i;
    }

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

    // precompute L
    DFS(root, 0);

    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    // if(n > 50000)
    // assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      if(n < 10000)
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

    // precompute L
    DFS(root, 0);

    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    if(n > 50000)
    assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      if(n < 10000)
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);
    for(int i = 0; i < n; i++)
    {
      int p;
      // read p, the parent of node i or -1 if node i is the root
      if(parent[i] == -2)
        p = -1;
      else
        p = parent[i];
      A[i][0] = p;
      if(p != -1)
          g[p].push_back(i);
      else
          root = i;
    }

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

    // precompute L
    DFS(root, 0);
            if(n>10000)
    assert(0);

    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    if(n > 50000)
    assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      if(n < 10000)
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);
    for(int i = 0; i < n; i++)
    {
      int p;
      // read p, the parent of node i or -1 if node i is the root
      if(parent[i] == -2)
        p = -1;
      else
        p = parent[i];
      A[i][0] = p;
      if(p != -1)
          g[p].push_back(i);
      else
          root = i;
    }

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

        if(n>10000)
    assert(0);

    // precompute L
    DFS(root, 0);
    // if(n > 10000)
    // assert(0);
    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    if(n > 50000)
    assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);
    for(int i = 0; i < n; i++)
    {
      int p;
      // read p, the parent of node i or -1 if node i is the root
      if(parent[i] == -2)
        p = -1;
      else
        p = parent[i];
      A[i][0] = p;
      if(p != -1)
          g[p].push_back(i);
      else
          root = i;
    }

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

    // precompute L
    DFS(root, 0);

    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    if(n > 50000)
    assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])
#define md 1000000007
#define MAXN 100005
#define log_MAXN 16

#define pr16

#ifdef pr16
  #define pr(x)                 cerr << #x << ": " << x << endl;
  #define pr2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
  #define pr3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
  #define pr4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
  #define pr5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
  #define pr6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prc(a) tr(a, it) cerr<<*(it)<<" "; cerr<<endl
  #define pra(a,n) for(int i=0; i<(n); i++) cerr<<((a)[i])<<" "; cerr<<"\n"
  #define prdd(a,r,c) for(int i=0;i<(r);i++) { for(int j = 0;j<(c);j++) cerr<<a[i][j]<<" "; cerr<<endl; } cerr<<endl;
  #define prddd(a,x,y,z) for(int i=0;i<x;i++) {cerr<<"layer "<<i<<":\n";prdd(a[i],y,z)}

#else
  #define pr(x)
  #define pr2(x, y)
  #define pr3(x, y, z)
  #define pr4(a, b, c, d)
  #define pr5(a, b, c, d, e)
  #define pr6(a, b, c, d, e, f)
  #define tr(c,it)
  #define prc(a)
  #define pra(a,n)
  #define prdd(a, r, c)
  #define prddd(a,x,y,z)
#endif

int n, logn, root;

vector<int> g[MAXN];  // g[i] contains the g of node i
int A[MAXN][log_MAXN+1];  // A[i][j] is the 2^j-th ancestor of node i, or -1 if that ancestor does not exist
int L[MAXN];     // L[i] is the distance between node i and the root

int parent[100001];
// vi g[100001];

// floor of the binary logarithm of n
int lb(unsigned int n)
{
    if(n==0)
  return -1;
    int p = 0;
    if (n >= 1<<16) { n >>= 16; p += 16; }
    if (n >= 1<< 8) { n >>=  8; p +=  8; }
    if (n >= 1<< 4) { n >>=  4; p +=  4; }
    if (n >= 1<< 2) { n >>=  2; p +=  2; }
    if (n >= 1<< 1) {           p +=  1; }
    return p;
}

void DFS(int i, int l)
{
    L[i] = l;
    for(int j = 0; j < g[i].size(); j++)
      if(g[i][j] != parent[i])
  DFS(g[i][j], l+1);
}

int LCA(int p, int q)
{
    // ensure node p is at least as deep as node q
    if(L[p] < L[q])
  swap(p, q);

    // "binary search" for the ancestor of node p situated on the same level as q
    for(int i = logn; i >= 0; i--)
  if(L[p] - (1<<i) >= L[q])
      p = A[p][i];

    if(p == q)
  return p;

    // "binary search" for the LCA
    for(int i = logn; i >= 0; i--)
  if(A[p][i] != -1 && A[p][i] != A[q][i])
  {
      p = A[p][i];
      q = A[q][i];
  }

    return A[p][0];
}

void fn(int s)
{
  rep(i,g[s].size())
    if(parent[g[s][i]]==-1)
    {
      parent[g[s][i]] = s;
      fn (g[s][i]);
    }
}

int main()
{
    // read n, the total number of nodes
    cin>>n;
    logn=lb(n);

    map<pii,int> dic;
    rep(i,n-1)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;
      if(t1 < t2)
        swap(t1,t2);
      if(n < 10000)
      dic[mp(t1,t2)] = i;
      g[t1].pb(t2);
      g[t2].pb(t1);
    }
    MEM(parent,-1);
    parent[0] = -2;
    fn(0);
    for(int i = 0; i < n; i++)
    {
      int p;
      // read p, the parent of node i or -1 if node i is the root
      if(parent[i] == -2)
        p = -1;
      else
        p = parent[i];
      A[i][0] = p;
      if(p != -1)
          g[p].push_back(i);
      else
          root = i;
    }

    // precompute A using dynamic programming
    for(int j = 1; j <= logn; j++)
      for(int i = 0; i < n; i++)
        if(A[i][j-1] != -1)
          A[i][j] = A[A[i][j-1]][j-1];
        else
          A[i][j] = -1;

    // precompute L
    DFS(root, 0);

    // pr(LCA(3,4));
    int a[n];
    int ans[n];
    MEM(a,0);
    int m;
    cin>>m;

    rep(i,m)
    {
      int t1,t2;
      cin>>t1>>t2;
      t1--;t2--;

      a[t1]++,a[t2]++;
      a[LCA(t1,t2)] -= 2;
    }

    set<pii> s;
    set<int> G[n];
    rep(i,n)
      rep(j,g[i].size())
        G[i].insert(g[i][j]);

    loop(i,1,n)
    {
      s.insert(mp(g[i].size(),i));
    }

    if(n > 50000)
    assert(0);

    rep(it,n-1)
    {
      pii cur = *(s.begin());
      int el = cur.Y;
      // pr(el);
      s.erase(cur);
      int el2 = *(G[el].begin());
      G[el2].erase(el);
      a[el2] += a[el];
      if(el2 != 0)
      {
        s.erase(mp(G[el2].size()+1,el2));
        s.insert(mp(G[el2].size(),el2));
      }
    }
    // pra(a,n);

    int out[n-1];
    loop(i,1,n)
    {
      int t1 = i,t2 = parent[i];
      if(i < parent[i])
        swap(t1,t2);
      // pr2(t1,t2);
      out[dic[mp(t1,t2)]] = a[i];
    }

    rep(i,n-1)
      cout<<out[i]<<" ";
      cout<<"\n";

    return 0;
}