#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][200055],level[200055];
int size,first[200055],next[400055];
int d[200055],res[200055];

struct edge {
    int to,idd;
};

edge e[400055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    if (n>1000)printf("diu");
    lca_init();
    if (n>1000)printf("wtfdiu");
    cin >> k;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    if (n>1000) printf("HOLYSHIT");
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][200055],level[200055];
int size,first[200055],next[400055];
int d[200055],res[200055];

struct edge {
    int to,idd;
};

edge e[400055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    lca_init();
    cin >> k;
    if (n>1000) cout << "DIU" << endl;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    if (n>1000) cout << "DIU" << endl;
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][200055],level[200055];
int size,first[200055],next[400055];
int d[200055],res[200055];

struct edge {
    int to,idd;
};

edge e[400055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    lca_init();
    cin >> k;
    if (n>1000) cout << "DIU";
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][100055],level[100055];
int size,first[100055],next[200055];
int d[100055],res[100055];

struct edge {
    int to,idd;
};

edge e[200055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    lca_init();
    cin >> k;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    if (n>1000) cout << "DIU" << endl;
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][200055],level[200055];
int size,first[200055],next[400055];
int d[200055],res[200055];

struct edge {
    int to,idd;
};

edge e[400055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    lca_init();
    cin >> k;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][100055],level[100055];
int size,first[100055],next[200055];
int d[100055],res[100055];

struct edge {
    int to,idd;
};

edge e[200055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    lca_init();
    cin >> k;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    solve(0,-1);
    cout << "DIU" << endl;
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <map>
#include <cmath>
#include <cstdlib>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <climits>
#include <cctype>
#include <utility>
using namespace std;

#define ft first
#define sd second
#define pb push_back
#define endl '\n'
#define cpy(a,e) memcpy(a,e,sizeof(e))
#define clr(a,e) memset(a,e,sizeof(a))
#define iter(c) __typeof((c).begin())
#define tr(c,i) for (iter(c) i=(c).begin();i!=(c).end();i++)
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define repd(i,n) for (int (i)=(n)-1;(i)>=0;i--)
#define reps(i,s,e) for (int (i)=(s);(i)<=(e);i++)
#define repds(i,s,e) for (int (i)=(s);(i)>=(e);i--)
#define repl(i,s,e) for (int (i)=(s);(i);i=e[i])

int n,k,par[19][200055],level[200055];
int size,first[200055],next[400055];
int d[200055],res[200055];

struct edge {
    int to,idd;
};

edge e[400055];

void add_edge(int from,int to,int id) {
    next[++size]=first[from];
    first[from]=size;
    e[size]=(edge){to,id};
}
void dfs(int id,int p,int d) {
    level[id]=d;
    par[0][id]=p;
    repl(i,first[id],next) {
        int to=e[i].to;
        if (to==p) continue;
        dfs(to,id,d+1);
    }
}
void lca_init() {
    dfs(0,-1,0);
    rep(i,17) {
        rep(v,n) {
            if (par[i][v]==-1) par[i+1][v]=-1;
            else par[i+1][v]=par[par[i][v]][v];
        }
    }
}
int lca(int u,int v) {
    if (level[u]>level[v]) swap(u,v);
    rep(i,18) {
        if (((level[v]-level[u])>>i)&1) {
            v=par[i][v];
        }
    }
    if (u==v) return u;
    repd(i,18) {
        if (par[i][u]!=par[i][v]) {
            u=par[i][u];
            v=par[i][v];
        }
    }
    return par[0][u];
}
void solve(int id,int par) {
    repl(i,first[id],next) {
        int to=e[i].to,idd=e[i].idd;
        if (to==par) continue;
        solve(to,id);
        res[idd]=d[to];
        d[id]+=d[to];
    }
}
int main() {
    cin >> n;
    int x,y;
    rep(i,n-1) {
        cin >> x >> y;
        x--;y--;
        if (n>1000) printf("aiorjwiodj");
        add_edge(x,y,i);
        add_edge(y,x,i);
    }
    if (n>1000)printf("diu");
    lca_init();
    if (n>1000)printf("wtfdiu");
    cin >> k;
    while(k--) {
        cin >> x >> y;
        x--;y--;
        int l=lca(x,y);
        d[l]-=2;
        d[x]++;d[y]++;
    }
    if (n>1000) printf("HOLYSHIT");
    solve(0,-1);
    rep(i,n-1) {
        if (i) cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

vector<vector<int> > G;
vector<int> Z;
vector<int> K;
vector<bool> T;
vector<vector<int> > S;
vector<int> V;
vector<int> H;
vector<int> P;
vector<pair<int,int> > E;
int cas=0;

void dfs(int v)
{
  T[v]=true;
  Z[v]=cas;
  for(int i=0; i<G[v].size(); i++)
  {
    int w=G[v][i];
    if(T[w]) continue;
    cas++;
    S[w][0]=v;
    dfs(w);
  }
  cas++;
  K[v]=cas;
}

void dfs2(int v)
{
  T[v]=true;
  int vys=0;
  for(int i=0; i<G[v].size(); i++)
  {
    if(!T[G[v][i]]) dfs2(G[v][i]);
    vys+=P[G[v][i]];
  }
  P[v]=vys+H[v];
}

int main()
{
  int n;
  scanf("%d ",&n);
  G.resize(n);
  T.resize(n,false);
  Z.resize(n);
  K.resize(n);
  V.resize(n,0);
  P.resize(n,0);
  S.resize(n);
  for(int i=0; i<n; i++) S[i].resize(32,-1);
  for(int i=0; i<n-1; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
    E.push_back(make_pair(x,y));
  }
  dfs(0);
  int p=1;
  while(p<=30)
  {
    for(int i=0; i<n; i++)
    {
      if(S[i][p-1]!=-1) S[i][p]=S[S[i][p-1]][p-1];
    }
    p++;
  }
  H.resize(n,0);
  int m;
  scanf("%d ",&m);
  for(int i=0; i<m; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    if(x==y) continue;
    x--; y--;
    if(Z[x]<Z[y] && K[x]>K[y]) {H[x]--; H[y]++; continue;}
    if(Z[x]>Z[x] && K[x]<K[y]) {H[x]++; H[y]--; continue;}
    int zac=x;
    int p1=30;
    while(p1!=-1)
    {
      if(S[zac][p1]==-1) {p1--; continue;}
      int w=S[zac][p1];
      if(Z[w]<Z[y] && K[w]>K[y]) {p1--; continue;}
      zac=w;
    }
    H[x]++; H[y]++; H[S[zac][0]]-=2;
  }
  T.clear(); T.resize(n,false);
  dfs2(0);
  for(int i=0; i<E.size(); i++)
  {
    int v=E[i].first,w=E[i].second;
    if(Z[v]<Z[w]) printf("%d",P[w]);
    else printf("%d",P[v]);
    if(i==E.size()-1) printf("\n");
    else printf(" ");
  }
return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

vector<vector<int> > G;
vector<int> Z;
vector<int> K;
vector<bool> T;
vector<vector<int> > S;
vector<int> V;
vector<int> H;
vector<int> P;
vector<pair<int,int> > E;
int cas=0;

void dfs(int v)
{
  T[v]=true;
  Z[v]=cas;
  for(int i=0; i<G[v].size(); i++)
  {
    int w=G[v][i];
    if(T[w]) continue;
    cas++;
    S[w][0]=v;
    dfs(w);
  }
  cas++;
  K[v]=cas;
}

void dfs2(int v)
{
  T[v]=true;
  int vys=0;
  for(int i=0; i<G[v].size(); i++)
  {
    if(!T[G[v][i]]) dfs2(G[v][i]);
    vys+=P[G[v][i]];
  }
  P[v]=vys+H[v];
}

int main()
{
  int n;
  scanf("%d ",&n);
  G.resize(n);
  T.resize(n,false);
  Z.resize(n);
  K.resize(n);
  V.resize(n,0);
  P.resize(n,0);
  S.resize(n);
  for(int i=0; i<n; i++) S[i].resize(32,-1);
  for(int i=0; i<n-1; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
    E.push_back(make_pair(x,y));
  }
  dfs(0);
  int p=1;
  while(p<=30)
  {
    for(int i=0; i<n; i++)
    {
      if(S[i][p-1]!=-1) S[i][p]=S[S[i][p-1]][p-1];
    }
    p++;
  }
  H.resize(n,0);
  int m;
  scanf("%d ",&m);
  for(int i=0; i<m; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    if(Z[x]<Z[y] && K[x]>K[y]) {H[x]--; H[y]++; continue;}
    if(Z[x]>Z[x] && K[x]<K[y]) {H[x]++; H[y]--; continue;}
    int zac=x;
    int p1=30;
    while(p1!=-1)
    {
      if(S[zac][p1]==-1) {p1--; continue;}
      int w=S[zac][p1];
      if(Z[w]<Z[y] && K[w]>K[y]) {p1--; continue;}
      zac=w;
    }
    H[x]++; H[y]++; H[S[zac][0]]-=2;
  }
  T.clear(); T.resize(n,false);
  dfs2(0);
  for(int i=0; i<E.size(); i++)
  {
    int v=E[i].first,w=E[i].second;
    if(Z[v]<Z[w]) printf("%d",P[w]);
    else printf("%d",P[v]);
    if(i==E.size()-1) printf("\n");
    else printf(" ");
  }
return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

vector<vector<int> > G;
vector<int> Z;
vector<int> K;
vector<bool> T;
vector<vector<int> > S;
vector<int> V;
vector<int> P;
map<pair<int,int>,int> M;
int cas=0;

void dfs(int v)
{
  T[v]=true;
  Z[v]=cas;
  for(int i=0; i<G[v].size(); i++)
  {
    if(T[G[v][i]]==false) {S[G[v][i]][0]=v; cas++; dfs(G[v][i]);}
  }
  cas++;
  K[v]=cas;
}

int main()
{
  int n;
  scanf("%d ",&n);
  G.resize(n);
  T.resize(n,false);
  Z.resize(n);
  K.resize(n);
  V.resize(n,0);
  P.resize(n,0);
  for(int i=0; i<n-1; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    M[make_pair(x,y)]=i;
    M[make_pair(y,x)]=i;
    P[x]++; P[y]++;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  S.resize(n);
  for(int i=0; i<n; i++) S[i].resize(30,-1);
  dfs(0);
  int p=1;
  while((1<<p)<=n)
  {
    for(int i=0; i<n; i++)
    {
      if(S[i][p-1]!=-1) S[i][p]=S[S[i][p-1]][p-1];
    }
    p++;
  }
  int k;
  scanf("%d ",&k);
  vector<int> H; H.resize(n,0);
  for(int i=0; i<k; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    if(Z[x]<Z[y] && K[y]<K[x]) {H[x]--; H[y]++; continue;}
    if(Z[y]<Z[x] && K[x]<K[y]) {H[x]++; H[y]--; continue;}
    int zac=x,kon=0,kolko=p;
    while(kolko!=-1)
    {
      if(S[zac][kolko]==-1) {kolko--; continue;}
      int v=S[zac][kolko];
      if(Z[v]<Z[y] && K[y]<K[v]) {kolko--;}
      else zac=v;
    }
    H[x]++; H[y]++; H[S[zac][0]]-=2;
  }
  //uz to len dokonci
  P[0]++;
  T.clear();
  T.resize(n,false);
  queue<int> Q;
  for(int i=0; i<n; i++)
  {
    if(P[i]==1) {T[i]=true; Q.push(i);}
  }
  while(!Q.empty())
  {
    int v=Q.front(); Q.pop();
    if(v==0) continue;
    T[v]=true;
    int w=S[v][0];
    pair<int,int> a=make_pair(v,w);
    int kde=M[a];
    V[kde]+=H[v];
    H[w]+=H[v];
    P[w]--;
    if(P[w]==1) {Q.push(w);}
  }
  printf("%d",V[0]);
  for(int i=1; i<n-1; i++) printf(" %d",V[i]); printf("\n");
return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

vector<vector<int> > G;
vector<int> Z;
vector<int> K;
vector<bool> T;
vector<vector<int> > S;
vector<int> V;
vector<int> H;
vector<int> P;
vector<pair<int,int> > E;
int cas=0;

void dfs(int v)
{
  T[v]=true;
  Z[v]=cas;
  for(int i=0; i<G[v].size(); i++)
  {
    int w=G[v][i];
    if(T[w]) continue;
    cas++;
    S[w][0]=v;
    dfs(w);
  }
  cas++;
  K[v]=cas;
}

void dfs2(int v)
{
  T[v]=true;
  int vys=0;
  for(int i=0; i<G[v].size(); i++)
  {
    if(!T[G[v][i]]) dfs2(G[v][i]);
    vys+=P[G[v][i]];
  }
  P[v]=vys+H[v];
}

int main()
{
  int n;
  scanf("%d ",&n);
  G.resize(n);
  T.resize(n,false);
  Z.resize(n);
  K.resize(n);
  V.resize(n,0);
  P.resize(n,0);
  S.resize(n);
  for(int i=0; i<n; i++) S[i].resize(30,-1);
  for(int i=0; i<n-1; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
    E.push_back(make_pair(x,y));
  }
  dfs(0);
  int p=1;
  while((1<<p)<=n)
  {
    for(int i=0; i<n; i++)
    {
      if(S[i][p-1]!=-1) S[i][p]=S[S[i][p-1]][p-1];
    }
    p++;
  }
  H.resize(n,0);
  int m;
  scanf("%d ",&m);
  for(int i=0; i<m; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    if(Z[x]<Z[y] && K[x]>K[y]) {H[x]--; H[y]++; continue;}
    if(Z[x]>Z[x] && K[x]<K[y]) {H[x]++; H[y]--; continue;}
    int zac=x;
    int p1=p;
    while(p1!=-1)
    {
      if(S[zac][p1]==-1) {p1--; continue;}
      int w=S[zac][p1];
      if(Z[w]<Z[y] && K[w]>K[y]) {p1--; continue;}
      zac=w;
    }
    H[x]++; H[y]++; H[S[zac][0]]-=2;
  }
  T.clear(); T.resize(n,false);
  dfs2(0);
  for(int i=0; i<E.size(); i++)
  {
    int v=E[i].first,w=E[i].second;
    if(Z[v]<Z[w]) printf("%d",P[w]);
    else printf("%d",P[v]);
    if(i==E.size()-1) printf("\n");
    else printf(" ");
  }
return 0;
}


#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <queue>
using namespace std;

vector<vector<int> > G;
vector<int> Z;
vector<int> K;
vector<bool> T;
vector<vector<int> > S;
vector<int> V;
vector<int> H;
vector<int> P;
vector<pair<int,int> > E;
int cas=0;

void dfs(int v)
{
  T[v]=true;
  Z[v]=cas;
  for(int i=0; i<G[v].size(); i++)
  {
    int w=G[v][i];
    if(T[w]) continue;
    cas++;
    S[w][0]=v;
    dfs(w);
  }
  cas++;
  K[v]=cas;
}

void dfs2(int v)
{
  T[v]=true;
  int vys=0;
  for(int i=0; i<G[v].size(); i++)
  {
    if(!T[G[v][i]]) dfs2(G[v][i]);
    vys+=P[G[v][i]];
  }
  P[v]=vys+H[v];
}

int main()
{
  int n;
  scanf("%d ",&n);
  G.resize(n);
  T.resize(n,false);
  Z.resize(n);
  K.resize(n);
  V.resize(n,0);
  P.resize(n,0);
  S.resize(n);
  for(int i=0; i<n; i++) S[i].resize(32,-1);
  for(int i=0; i<n-1; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    x--; y--;
    G[x].push_back(y);
    G[y].push_back(x);
    E.push_back(make_pair(x,y));
  }
  dfs(0);
  int p=1;
  while(p<=30)
  {
    for(int i=0; i<n; i++)
    {
      if(S[i][p-1]!=-1) S[i][p]=S[S[i][p-1]][p-1];
    }
    p++;
  }
  H.resize(n,0);
  int m;
  scanf("%d ",&m);
  for(int i=0; i<m; i++)
  {
    int x,y;
    scanf("%d %d ",&x,&y);
    if(x==y) continue;
    x--; y--;
    if(Z[x]<Z[y] && K[x]>K[y]) {H[x]--; H[y]++; continue;}
    if(Z[x]>Z[x] && K[x]<K[y]) {H[x]++; H[y]--; continue;}
    int zac=x;
    int p1=30;
    while(p1!=-1)
    {
      if(S[zac][p1]==-1) {p1--; continue;}
      int w=S[zac][p1];
      if(Z[w]<Z[y] && K[w]>K[y]) {p1--; continue;}
      zac=w;
    }
    int w=zac;
    while(Z[w]>Z[y] || K[w]<K[y])
    {
      w=S[w][0];
    }
    H[x]++; H[y]++; H[w]-=2;
  }
  T.clear(); T.resize(n,false);
  dfs2(0);
  for(int i=0; i<E.size(); i++)
  {
    int v=E[i].first,w=E[i].second;
    if(Z[v]<Z[w]) printf("%d",P[w]);
    else printf("%d",P[v]);
    if(i==E.size()-1) printf("\n");
    else printf(" ");
  }
return 0;
}


#include<iostream>
#include<cstdio>
using namespace std;
int i,a,b,n,kkk,fa[100001],q[100001],kk[200001],hi[100001],ans[100001],next[200001],till[100001],go[200001],len;
bool used[100001];
void add(int a,int b,int c)
{
	len++;
	next[len]=till[a];
	till[a]=len;
	go[len]=b;
	kk[len]=c;
	len++;
	next[len]=till[b];
	till[b]=len;
	go[len]=a;
	kk[len]=c;
}
void f(int p,int h)
{
	used[p]=true;
	hi[p]=h;
	int i=till[p];
	while (i)
	{
		if (!used[go[i]])
		{
			q[go[i]]=kk[i];
			fa[go[i]]=p;
			f(go[i],h+1);
		}
		i=next[i];
	}
}
void g(int a,int b)
{
	while (hi[a]>hi[b])
	{
		ans[q[a]]++;
		a=fa[a];
	}
	while (hi[a]<hi[b])
	{
		ans[q[b]]++;
		b=fa[b];
	}
	while (a!=b)
	{
		ans[q[b]]++;
		b=fa[b];
		ans[q[a]]++;
		a=fa[a];
	}
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		add(a,b,i);
	}
	f(1,1);
	scanf("%d",&kkk);
	while (kkk--)
	{
		scanf("%d%d",&a,&b);
		g(a,b);
	}
	for (i=1;i<n;i++)
	printf("%d ",ans[i]);
}


#include<iostream>
#include<cstdio>
using namespace std;
int i,a,b,n,kkk,fa[100001],q[100001],kk[200001],hi[100001],ans[100001],next[200001],till[100001],go[200001],len;
bool used[100001];
void add(int a,int b,int c)
{
	len++;
	next[len]=till[a];
	till[a]=len;
	go[len]=b;
	kk[len]=c;
	len++;
	next[len]=till[b];
	till[b]=len;
	go[len]=a;
	kk[len]=c;
}
void f(int p,int h)
{
	used[p]=true;
	hi[p]=h;
	int i=till[p];
	while (i)
	{
		if (!used[go[i]])
		{
			q[go[i]]=kk[i];
			fa[go[i]]=p;
			f(go[i],h+1);
		}
		i=next[i];
	}
}
void g(int a,int b)
{
	while (hi[a]>hi[b])
	{
		ans[q[a]]++;
		a=fa[a];
	}
	while (hi[a]<hi[b])
	{
		ans[q[b]]++;
		b=fa[b];
	}
	while (a!=b)
	{
		ans[q[b]]++;
		b=fa[b];
		ans[q[a]]++;
		a=fa[a];
	}
}
int main()
{
	scanf("%d",&n);
	for (i=1;i<n;i++)
	{
		scanf("%d%d",&a,&b);
		add(a,b,i);
	}
	f(n/2,1);
	scanf("%d",&kkk);
	while (kkk--)
	{
		scanf("%d%d",&a,&b);
		g(a,b);
	}
	for (i=1;i<n;i++)
	printf("%d ",ans[i]);
}


#include <cstdio>
#include <vector>
using namespace std;

#define N 210000
int n, i, a, b, k, len, Time, s[N], sum[N], ans[N], fa[N], till[N], go[N], next[N];
bool used[N];
vector <int> ve[N];

void add(int a, int b) {
	next[++len] = till[a];
	till[a] = len;
	go[len] = b;
}

int gf(int x) {
	if (fa[x] != x)	fa[x] = gf(fa[x]);
	return fa[x];
}

void tarjan(int k, int ff) {
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1) tarjan(go[i], i), fa[go[i]] = k;
	used[k] = true;
	for (int i = 0; i < ve[k].size(); i++)
		if (used[ve[k][i]])	s[gf(ve[k][i])] -= 2;
}

void dfs(int k, int ff) {
	int now = Time;
	sum[Time + 1] = sum[Time] + s[k];
	Time++;
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1)	dfs(go[i], i);
	ans[ff / 2] = sum[Time] - sum[now];
}

int main() {
	// freopen("191C.in", "r", stdin);
	scanf("%d", &n);
	len = 1;
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		add(a, b);
		add(b, a);
	}
	for (i = 1; i <= n; i++)	fa[i] = i;
	scanf("%d", &k);
	for (i = 1; i <= k; i++) {
		scanf("%d%d", &a, &b);
		s[a]++; s[b]++;
		ve[a].push_back(b);
		if (a != b)	ve[b].push_back(a);
	}
	tarjan(1, 0);
	dfs(1, 0);
	for (i = 1; i < n; i++)	printf("%d ", ans[i]);
}


#include <cstdio>
#include <vector>
using namespace std;

#define N 210000
int n, i, a, b, k, len, Time, s[N], sum[N], ans[N], fa[N], till[N], go[N], next[N];
bool used[N];
vector <int> ve[N];

void add(int a, int b) {
	next[++len] = till[a];
	till[a] = len;
	go[len] = b;
}

int gf(int x) {
	if (fa[x] != x)	fa[x] = gf(fa[x]);
	return fa[x];
}

void tarjan(int k, int ff) {
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1) tarjan(go[i], i), fa[go[i]] = k;
	used[k] = true;
	for (int i = 0; i < ve[k].size(); i++)
		if (used[ve[k][i]])	s[gf(ve[k][i])] -= 2;
}

void dfs(int k, int ff) {
	int now = Time;
	sum[Time + 1] = sum[Time] + s[k];
	Time++;
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1)	dfs(go[i], i);
	ans[ff / 2] = sum[Time] - sum[now];
}

int main() {
	// freopen("191C.in", "r", stdin);
	scanf("%d", &n);
	len = 1;
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		add(a, b);
		add(b, a);
	}
	for (i = 1; i <= n; i++)	fa[i] = i;
	scanf("%d", &k);
	for (i = 1; i <= k; i++) {
		scanf("%d%d", &a, &b);
		s[a]++; s[b]++;
		ve[a].push_back(b);
		ve[b].push_back(a);
	}
	tarjan(1, 0);
	dfs(1, 0);
	for (i = 1; i < n; i++)	printf("%d ", ans[i]);
}


#include <cstdio>
#include <vector>
using namespace std;

#define N 210000
int n, i, a, b, k, len, Time, s[N], sum[N], ans[N], fa[N], till[N], go[N], next[N];
bool used[N];
vector <int> ve[N];

void add(int a, int b) {
	next[++len] = till[a];
	till[a] = len;
	go[len] = b;
}

int gf(int x) {
	if (fa[x] != x)	fa[x] = gf(fa[x]);
	return fa[x];
}

void tarjan(int k, int ff) {
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1) tarjan(go[i], i), fa[go[i]] = k;
	for (int i = 0; i < ve[k].size(); i++)
		if (used[ve[k][i]])	s[gf(ve[k][i])] -= 2;
	used[k] = true;
}

void dfs(int k, int ff) {
	int now = Time;
	sum[Time + 1] = sum[Time] + s[k];
	Time++;
	for (int i = till[k]; i; i = next[i])
		if ((i ^ ff) != 1)	dfs(go[i], i);
	ans[ff / 2] = sum[Time] - sum[now];
}

int main() {
	scanf("%d", &n);
	len = 1;
	for (i = 1; i < n; i++) {
		scanf("%d%d", &a, &b);
		add(a, b);
		add(b, a);
	}
	for (i = 1; i <= n; i++)	fa[i] = i;
	scanf("%d", &k);
	for (i = 1; i <= k; i++) {
		scanf("%d%d", &a, &b);
		s[a]++; s[b]++;
		ve[a].push_back(b);
		ve[b].push_back(a);
	}
	tarjan(1, 0);
	dfs(1, 0);
	for (i = 1; i < n; i++)	printf("%d ", ans[i]);
}


#include <bits/stdc++.h>
#define I(c) (int(c)-'0')
#define F first
#define S second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+10,maxbit=20;
int val[maxn],flag[maxn];
vector <pii> v[maxn];
int par[maxn][maxbit];
int ans[maxn];
inline int dfs(int x,int p,int id)
{
    int ret=val[x];
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            ret+=dfs(v[x][i].F,x,v[x][i].S);
    ans[id]=ret;
    return ret;
}

inline int dfs_(int x,int p)
{
    par[x][0]=p;
    for(int i=1;i<maxbit;i++)
        par[x][i]=par[par[x][i-1]][i-1];
    flag[x]=flag[p]+1;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            dfs_(v[x][i].F,x);
}

inline int Par(int k,int x)
{
    k=flag[x]-k;
    for(int i=0;i<maxbit;i++)
        if(k&(1<<i))
            x=par[x][i];
    return x;
}

inline int LCA(int x,int y)
{
    if(flag[x]<flag[y])
        swap(x,y);
    x=Par(flag[y],x);
    if(x==y)
        return y;
    for(int i=maxbit-1;i>=0;i--)
        if(par[x][i]!=par[y][i])
        {
            x=par[x][i];
            y=par[y][i];
        }
    return par[x][0];
}

int main()
{
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(pii(y,i));
        v[y].push_back(pii(x,i));
    }
    int q;
    cin>>q;
    dfs_(1,0);
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(flag[x]<flag[y])
            swap(x,y);
        val[x]++;
        val[y]++;
        val[LCA(x,y)]-=2;

    }
    dfs(1,0,0);
    for(int i=1;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


//in the name of God

#include<bits/stdc++.h>

#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

typedef pair<int , int> pii;

const int maxn = 1e5 + 17;
const int maxlog = 20;

int S[maxn];
int Ans[maxn];
int High[maxn];
int Par[maxn][maxlog];

vector<int> V[maxn];

map<pii , int> mp;

inline void dfs(int x , int par)
{
    Par[x][0] = par;
    High[x] = High[par] + 1;
    for(int i = 1 ; i < maxlog ; i++)
        Par[x][i] = Par[Par[x][i - 1]][i - 1];

    for(int i = 0 ; i < V[x].size() ; i++)
        if(V[x][i] != par)
            dfs(V[x][i] , x);
}

inline int LCA(int x , int y)
{
    if(High[x] < High[y])
        swap(x ,y);
    for(int i = maxlog - 1 ; i>=0 ; i--)
        if(High[Par[x][i]] >= High[y])
            x = Par[x][i];

    if(x == y)
        return x;
    for(int i = maxlog - 1 ; i>=0 ; i--)
        if(Par[x][i] != Par[y][i]){
            x = Par[x][i];
            y = Par[y][i];
        }

    return Par[x][0];
}

inline int solve(int x , int par , int e)
{
    int ret = S[x];
    for(int i = 0 ; i < V[x].size() ; i++){
        int h = V[x][i];
        if(h == par)
            continue;
        ret += solve(h , x , mp[pii(x , h)]);
    }

    Ans[e] = ret;
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1 ; i < n ; i++){
        int fi , se;
        cin >> fi >> se;
        V[fi].pb(se);
        V[se].pb(fi);
        mp[pii(fi , se)] = i;
        mp[pii(se , fi)] = i;
    }

    dfs(1 , 0);

    int q;
    cin >> q;
    for(int i = 1 ; i <= q ; i++){
        int x , y;
        cin >> x >> y;
        S[x]++;
        S[y]++;
        S[LCA(x , y)] -= 2;
    }

    solve(1 , 0 , 0);
    for(int i = 1 ; i < n ; i++)
        cout << Ans[i] << " ";
}


#include <bits/stdc++.h>
#define I(c) (int(c)-'0')
#define F first
#define S second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+10,maxbit=20;
int val[maxn],flag[maxn];
vector <pii> v[maxn];
int par[maxn][maxbit];
int ans[maxn];
inline int dfs(int x,int p,int id)
{
    int ret=val[x];
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            ret+=dfs(v[x][i].F,x,v[x][i].S);
    ans[id]=ret;
    return ret;
}

inline int dfs_(int x,int p)
{
    par[x][0]=p;
    for(int i=1;i<maxbit;i++)
        par[x][i]=par[par[x][i-1]][i-1];
    flag[x]=flag[p]+1;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            dfs_(v[x][i].F,x);
}

inline int Par(int k,int x)
{
    k=flag[x]-k;
    for(int i=0;i<maxbit;i++)
        if(k&(1<<i))
            x=par[x][i];
    return x;
}

inline int LCA(int x,int y)
{
    if(flag[x]<flag[y])
        swap(x,y);
    x=Par(flag[y],x);
    if(x==y)
        return y;
    for(int i=maxbit-1;i>=0;i--)
        if(par[x][i]!=par[y][i])
        {
            x=par[x][i];
            y=par[y][i];
        }
    return par[x][0];
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(pii(y,i));
        v[y].push_back(pii(x,i));
    }
    int q;
    scanf("%d",&q);
    dfs_(1,0);
    while(q--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(flag[x]<flag[y])
            swap(x,y);
        val[x]++;
        val[y]++;
        val[LCA(x,y)]-=2;

    }
    dfs(1,0,0);
    for(int i=1;i<n;i++)
        printf("%d ",ans[i]);
    return 0;
}


#include <bits/stdc++.h>
#define I(c) (int(c)-'0')
#define F first
#define S second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+10,maxbit=20;
int val[maxn],flag[maxn];
vector <pii> v[maxn];
int par[maxn][maxbit];
int ans[maxn];
inline int dfs(int x,int p,int id)
{
    int ret=val[x];
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            ret+=dfs(v[x][i].F,x,v[x][i].S);
    ans[id]=ret;
    return ret;
}

inline int dfs_(int x,int p)
{
    par[x][0]=p;
    for(int i=1;i<maxbit;i++)
        par[x][i]=par[par[x][i-1]][i-1];
    flag[x]=flag[p]+1;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            dfs_(v[x][i].F,x);
}

inline int Par(int k,int x)
{
    k=flag[x]-k;
    for(int i=0;i<maxbit;i++)
        if(k&(1<<i))
            x=par[x][i];
    return x;
}

inline int LCA(int x,int y)
{
    if(flag[x]<flag[y])
        swap(x,y);
    x=Par(flag[y],x);
    if(x==y)
        return y;
    for(int i=maxbit-1;i>=0;i--)
        if(par[x][i]!=par[y][i])
        {
            x=par[x][i];
            y=par[y][i];
        }
    return par[x][0];
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(pii(y,i));
        v[y].push_back(pii(x,i));
    }
    int q;
    cin>>q;
    dfs_(1,0);
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(flag[x]<flag[y])
            swap(x,y);
        val[x]++;
        val[y]++;
        val[LCA(x,y)]-=2;

    }
    dfs(1,0,0);
    for(int i=1;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include <bits/stdc++.h>
#define I(c) (int(c)-'0')
#define F first
#define S second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+10,maxbit=20;
int val[maxn],flag[maxn];
vector <pii> v[maxn];
int par[maxn][maxbit];
int ans[maxn];
inline int dfs(int x,int p,int id)
{
    int ret=val[x];
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            ret+=dfs(v[x][i].F,x,v[x][i].S);
    ans[id]=ret;
    return ret;
}

inline int dfs_(int x,int p)
{
    par[x][0]=p;
    for(int i=1;i<maxbit;i++)
        par[x][i]=par[par[x][i-1]][i-1];
    flag[x]=flag[p]+1;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            dfs_(v[x][i].F,x);
}

inline int Par(int k,int x)
{
    k=flag[x]-k;
    for(int i=0;i<maxbit;i++)
        if(k&(1<<i))
            x=par[x][i];
    return x;
}

inline int LCA(int x,int y)
{
    if(flag[x]<flag[y])
        swap(x,y);
    x=Par(flag[y],x);
    if(x==y)
        return y;
    for(int i=maxbit-1;i>=0;i--)
        if(par[x][i]!=par[y][i])
        {
            x=par[x][i];
            y=par[y][i];
        }
    return par[x][0];
}

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        v[x].push_back(pii(y,i));
        v[y].push_back(pii(x,i));
    }
    int q;
    scanf("%d",&q);
    dfs_(1,0);
    while(q--)
    {
        int x,y;
        scanf("%d%d",&x,&y);
        if(flag[x]<flag[y])
            swap(x,y);
        val[x]++;
        val[y]++;
        val[LCA(x,y)]-=2;

    }
    dfs(1,0,0);
    for(int i=1;i<n;i++)
        printf("%d",ans[i]);
    return 0;
}


//in the name of God

#include<bits/stdc++.h>

#define F first
#define S second
#define ll long long
#define pb push_back

using namespace std;

typedef pair<int , int> pii;

const int maxn = 1e5 + 17;
const int maxlog = 20;

int S[maxn];
int Ans[maxn];
int High[maxn];
int Par[maxn][maxlog];

vector<int> V[maxn];

map<pii , int> mp;

inline void dfs(int x , int par)
{
    Par[x][0] = par;
    High[x] = High[par] + 1;
    for(int i = 1 ; i < maxlog ; i++)
        Par[x][i] = Par[Par[x][i - 1]][i - 1];

    for(int i = 0 ; i < V[x].size() ; i++)
        if(V[x][i] != par)
            dfs(V[x][i] , x);
}

inline int LCA(int x , int y)
{
    if(High[x] < High[y])
        swap(x ,y);
    for(int i = maxlog - 1 ; i ; i--)
        if(High[Par[x][i]] >= High[y])
            x = Par[x][i];

    if(x == y)
        return x;
    for(int i = maxlog - 1 ; i>=0 ; i--)
        if(Par[x][i] != Par[y][i]){
            x = Par[x][i];
            y = Par[y][i];
        }

    return Par[x][0];
}

inline int solve(int x , int par , int e)
{
    int ret = S[x];
    for(int i = 0 ; i < V[x].size() ; i++){
        int h = V[x][i];
        if(h == par)
            continue;
        ret += solve(h , x , mp[pii(x , h)]);
    }

    Ans[e] = ret;
    return ret;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for(int i = 1 ; i < n ; i++){
        int fi , se;
        cin >> fi >> se;
        V[fi].pb(se);
        V[se].pb(fi);
        mp[pii(fi , se)] = i;
        mp[pii(se , fi)] = i;
    }

    dfs(1 , 0);

    int q;
    cin >> q;
    for(int i = 1 ; i <= q ; i++){
        int x , y;
        cin >> x >> y;
        S[x]++;
        S[y]++;
        S[LCA(x , y)] -= 2;
    }

    solve(1 , 0 , 0);
    for(int i = 1 ; i < n ; i++)
        cout << Ans[i] << " ";
}


#include <bits/stdc++.h>
#define I(c) (int(c)-'0')
#define F first
#define S second
#define ll long long
using namespace std;
typedef pair<int,int> pii;
const int maxn=1e5+10,maxbit=20;
int val[maxn],flag[maxn];
vector <pii> v[maxn];
int par[maxn][maxbit];
int ans[maxn];
inline int dfs(int x,int p,int id)
{
    int ret=val[x];
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            ret+=dfs(v[x][i].F,x,v[x][i].S);
    ans[id]=ret;
    return ret;
}

inline int dfs_(int x,int p)
{
    par[x][0]=p;
    for(int i=1;i<maxbit;i++)
        par[x][i]=par[par[x][i-1]][i-1];
    flag[x]=flag[p]+1;
    for(int i=0;i<v[x].size();i++)
        if(v[x][i].F!=p)
            dfs_(v[x][i].F,x);
}

inline int Par(int k,int x)
{
    k=flag[x]-flag[k];
    for(int i=0;i<maxbit;i++)
        if(k&(1<<i))
            x=par[x][i];
    return x;
}

inline int LCA(int x,int y)
{
    if(flag[x]<flag[y])
        swap(x,y);
    x=Par(flag[y],x);
    if(x==y)
        return y;
    for(int i=maxbit-1;i>=0;i--)
        if(par[x][i]!=par[y][i])
        {
            x=par[x][i];
            y=par[y][i];
        }
    return par[x][0];
}

int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++)
    {
        int x,y;
        cin>>x>>y;
        v[x].push_back(pii(y,i));
        v[y].push_back(pii(x,i));
    }
    int q;
    cin>>q;
    dfs_(1,0);
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        if(flag[x]<flag[y])
            swap(x,y);
        int z=LCA(x,y);
        if(z==y)
        {
            val[x]++;
            val[y]--;
        }
        else
        {
            val[x]++;
            val[y]++;
            val[z]--;
            val[z]--;
        }
    }
    dfs(1,0,0);
    for(int i=1;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
int n,k,x,y;
int parent[17][100005];
int depth[100005];
int cnt[100005];
int ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		scanf("%d%d",&x,&y);
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		scanf("%d%d",&x,&y);
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	printf("%d ",ans[i]);
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k;
int parent[17][10005];
int depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	cout<<ans[i]<<" ";
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[17][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	cout<<ans[i]<<" ";
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[20][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	printf("%d ",ans[i]);
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[20][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	cout<<ans[i]<<' ';
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k;
int parent[17][100005];
int depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	printf("%d ",ans[i]);
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[20][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	scanf("%d",&k);
	for(int i=0;i<k;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	printf("%d ",ans[i]);
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[17][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	printf("%d ",ans[i]);
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k,parent[17][100005],depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	cout<<ans[i]<<" ";
	cout<<endl;
	//system("pause");
	return 0;
}


//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 0x3f3f3f3f
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n,k;
int parent[17][100005];
int depth[100005],cnt[100005],ans[100005];
vector<pair<int,int> > g[100005];
void dfs(int v,int p,int d){
	parent[0][v]=p;
	depth[v]=d;
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first!=p)
		dfs(g[v][i].first,v,d+1);
	}
}
void init(){
	dfs(0,-1,0);
	for(int j=0;j<17;j++){
		for(int i=0;i<n;i++)
		if(parent[j][i]<0)
		parent[j+1][i]=-1;
		else
		parent[j+1][i]=parent[j][parent[j][i]];
	}
}
int lca(int u,int v){
	if(depth[u]>depth[v])
	swap(u,v);
	for(int i=0;i<17;i++){
		if((depth[v]-depth[u])&(1 << i))
		v=parent[i][v];
	}
	if(u==v)
	return u;
	for(int i=17;i>=0;i--){
		if(parent[i][u]!=parent[i][v]){
			u=parent[i][u];
			v=parent[i][v];
		}
	}
	return parent[0][u];
}
void get_ans(int v,int p){
	for(int i=0;i<g[v].size();i++){
		if(g[v][i].first==p)
		continue;
		get_ans(g[v][i].first,v);
		cnt[v]+=cnt[g[v][i].first];
		ans[g[v][i].second]=cnt[g[v][i].first];
	}
}
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		g[x].push_back(make_pair(y,i));
		g[y].push_back(make_pair(x,i));
	}
	init();
	cin>>k;
	for(int i=0;i<k;i++){
		int x,y;
		cin>>x>>y;
		x--;
		y--;
		int res=lca(x,y);
		cnt[x]++;
		cnt[y]++;
		cnt[res]-=2;
	}
	get_ans(0,-1);
	for(int i=0;i<n-1;i++)
	cout<<ans[i]<<" ";
	//system("pause");
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define maxn 100500
#define maxk 20

using namespace std;

vector < pair < int, int > > edge[maxn];
int par[maxn][maxk];
bool used[maxn];
int n, k;
int tin[maxn], tout[maxn];
int cur = 0;
int beg[maxn], en[maxn];
int res[maxn];

int DFS (int x, int car) {
	tin[x] = ++cur;
	used[x] = true;
	par[x][0] = car;
	for (int i = 1; par[x][i - 1]; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS (edge[x][i].first, x);
	tout[x] = ++cur;
	return 0;
}

inline bool is_par (int x, int y) {
	return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int lca (int x, int y) {
	if (is_par (x, y)) return x;
	if (is_par (y, x)) return y;
	int ans = x;
	for (int i = 19; i >= 0; --i)
		if (par[ans][i] !=0 && !is_par (par[ans][i], y))
			ans = par[ans][i];
	return par[ans][0];
}

inline int add (int x, int y) {
	++beg[x];
	++en[y];
	return 0;
}

int DFS1 (int x, int num, int &cbeg, int &cen) {
	used[x] = true;
	int ebeg = beg[x], een = en[x];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS1 (edge[x][i].first, edge[x][i].second, ebeg, een);
	res[num] = een - ebeg;
	//assert (res[num] >= 0);
	cbeg += ebeg;
	cen += een;
	return 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		edge[i].clear ();
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		edge[a].push_back (make_pair (b, i));
		edge[b].push_back (make_pair (a, i));
	}
	memset (used, 0, sizeof (used));
	DFS (1, 0);
	scanf ("%d", &k);
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		int l_c_a = lca (a, b);
		//printf ("a b lca %d %d %d\n", a, b, l_c_a);
		add (l_c_a, a);
		add (l_c_a, b);
	}
	int abeg = 0, aen = 0;
	memset (used, 0, sizeof (used));
	DFS1 (1, 0, abeg, aen);
	for (int i = 1; i < n; ++i)
		printf ("%d ", res[i]);
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>

#define maxn 100500

using namespace std;

struct list {
	long long x;
	int id;
} sm[maxn];

int n, k;
long long b;
int used[maxn];
long long a[maxn];
long long sum[maxn];

bool cmp (const list &a, const list &b) {
	return (a.x > b.x || a.x == b.x && a.id < b.id);
}

int main () {
	ios_base::sync_with_stdio (false);
	cin >> n >> k >> b;
	for (int i = 0; i < n; ++i) {
		cin >> sm[i].x;
		a[i] = sm[i].x;
		sm[i].id = i + 1;
	}
	sort (sm, sm + n - 1, cmp);
	sum[0] = 0;
	for (int i = 1; i < n; ++i) {
		sum[i] = sum[i - 1] + sm[i - 1].x;
		used[sm[i - 1].id] = i;
	}
	for (int i = 1; i < n; ++i) {
		long long first_k = sum[k - 1];
		if (used[i] < k) {
			first_k = sum[k];
		} else {
			first_k += a[i - 1];
		}
		if (first_k > b) {
			cout << i << endl;
			return 0;
		}
	}
	cout << n;
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define maxn 100500
#define maxk 20

using namespace std;

vector < pair < int, int > > edge[maxn];
int par[maxn][maxk];
bool used[maxn];
int n, k;
int tin[maxn], tout[maxn];
int cur = 0;
int beg[maxn], en[maxn];
int res[maxn];

int DFS (int x, int car) {
	tin[x] = ++cur;
	used[x] = true;
	par[x][0] = car;
	for (int i = 1; i < maxk; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS (edge[x][i].first, x);
	tout[x] = ++cur;
	return 0;
}

bool is_par (int x, int y) {
	return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int lca (int x, int y) {
	if (is_par (x, y)) return x;
	if (is_par (y, x)) return y;
	int ans = x;
	for (int i = 19; i >= 0; --i)
		if (par[ans][i] !=0 && !is_par (par[ans][i], y))
			ans = par[ans][i];
	return par[ans][0];
}

int add (int x, int y) {
	++beg[x];
	++en[y];
	return 0;
}

int DFS1 (int x, int num, int &cbeg, int &cen) {
	used[x] = true;
	int ebeg = beg[x], een = en[x];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS1 (edge[x][i].first, edge[x][i].second, ebeg, een);
	res[num] = een - ebeg;
	//assert (res[num] >= 0);
	cbeg += ebeg;
	cen += een;
	return 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		edge[i].clear ();
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		edge[a].push_back (make_pair (b, i));
		edge[b].push_back (make_pair (a, i));
	}
	memset (used, 0, sizeof (used));
	DFS (1, 0);
	scanf ("%d", &k);
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		int l_c_a = lca (a, b);
		//printf ("a b lca %d %d %d\n", a, b, l_c_a);
		add (l_c_a, a);
		add (l_c_a, b);
	}
	int abeg = 0, aen = 0;
	memset (used, 0, sizeof (used));
	DFS1 (1, 0, abeg, aen);
	for (int i = 1; i < n; ++i)
		printf ("%d ", res[i]);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define maxn 100500
#define maxk 20

using namespace std;

vector < pair < int, int > > edge[maxn];
int par[maxn][maxk];
bool used[maxn];
int n, k;
int tin[maxn], tout[maxn];
int cur = 0;
int beg[maxn], en[maxn];
int res[maxn];

int DFS (int x, int car) {
	tin[x] = ++cur;
	used[x] = true;
	par[x][0] = car;
	for (int i = 1; par[x][i - 1]; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS (edge[x][i].first, x);
	tout[x] = ++cur;
	return 0;
}

bool is_par (int x, int y) {
	return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int lca (int x, int y) {
	if (is_par (x, y)) return x;
	if (is_par (y, x)) return y;
	int ans = x;
	for (int i = 19; i >= 0; --i)
		if (par[ans][i] !=0 && !is_par (par[ans][i], y))
			ans = par[ans][i];
	return par[ans][0];
}

int add (int x, int y) {
	++beg[x];
	++en[y];
	return 0;
}

int DFS1 (int x, int num, int &cbeg, int &cen) {
	used[x] = true;
	int ebeg = beg[x], een = en[x];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS1 (edge[x][i].first, edge[x][i].second, ebeg, een);
	res[num] = een - ebeg;
	//assert (res[num] >= 0);
	cbeg += ebeg;
	cen += een;
	return 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		edge[i].clear ();
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		edge[a].push_back (make_pair (b, i));
		edge[b].push_back (make_pair (a, i));
	}
	memset (used, 0, sizeof (used));
	DFS (1, 0);
	scanf ("%d", &k);
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		int l_c_a = lca (a, b);
		//printf ("a b lca %d %d %d\n", a, b, l_c_a);
		add (l_c_a, a);
		add (l_c_a, b);
	}
	int abeg = 0, aen = 0;
	memset (used, 0, sizeof (used));
	DFS1 (1, 0, abeg, aen);
	for (int i = 1; i < n; ++i)
		printf ("%d ", res[i]);
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define maxn 100500
#define maxk 20

using namespace std;

vector < pair < int, int > > edge[maxn];
int par[maxn][maxk];
bool used[maxn];
int n, k;
int tin[maxn], tout[maxn];
int cur = 0;
int beg[maxn], en[maxn];
int res[maxn];

int DFS (int x, int car) {
	tin[x] = ++cur;
	used[x] = true;
	par[x][0] = car;
	for (int i = 1; par[x][i - 1]; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS (edge[x][i].first, x);
	tout[x] = ++cur;
	return 0;
}

inline bool is_par (int x, int y) {
	return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int lca (int x, int y) {
	if (is_par (x, y)) return x;
	if (is_par (y, x)) return y;
	int ans = x;
	for (int i = 19; i >= 0; --i)
		if (par[ans][i] !=0 && !is_par (par[ans][i], y))
			ans = par[ans][i];
	return par[ans][0];
}

inline int add (int x, int y) {
	++beg[x];
	++en[y];
	return 0;
}

int DFS1 (int x, int num, int &cbeg, int &cen) {
	used[x] = true;
	int ebeg = beg[x], een = en[x];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS1 (edge[x][i].first, edge[x][i].second, ebeg, een);
	res[num] = een - ebeg;
	//assert (res[num] >= 0);
	cbeg += ebeg;
	cen += een;
	return 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		edge[i].clear ();
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		edge[a].push_back (make_pair (b, i));
		edge[b].push_back (make_pair (a, i));
	}
	memset (used, 0, sizeof (used));
	DFS (1, 0);
	scanf ("%d", &k);
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		int l_c_a = lca (a, b);
		//printf ("a b lca %d %d %d\n", a, b, l_c_a);
		add (l_c_a, a);
		add (l_c_a, b);
	}
	int abeg = 0, aen = 0;
	memset (used, 0, sizeof (used));
	DFS1 (1, 0, abeg, aen);
	for (int i = 1; i < n; ++i)
		printf ("%d ", res[i]);
	printf ("\n");
	return 0;
}


#include <cstdio>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>

#define maxn 100500
#define maxk 20

using namespace std;

vector < pair < int, int > > edge[maxn];
int par[maxn][maxk];
bool used[maxn];
int n, k;
int tin[maxn], tout[maxn];
int cur = 0;
int beg[maxn], en[maxn];
int res[maxn];

int DFS (int x, int car) {
	tin[x] = ++cur;
	used[x] = true;
	par[x][0] = car;
	for (int i = 1; par[x][i - 1]; ++i)
		par[x][i] = par[par[x][i - 1]][i - 1];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS (edge[x][i].first, x);
	tout[x] = ++cur;
	return 0;
}

inline bool is_par (int x, int y) {
	return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int lca (int x, int y) {
	if (is_par (x, y)) return x;
	if (is_par (y, x)) return y;
	int ans = x;
	for (int i = 19; i >= 0; --i)
		if (par[ans][i] !=0 && !is_par (par[ans][i], y))
			ans = par[ans][i];
	return par[ans][0];
}

inline int add (int x, int y) {
	++beg[x];
	++en[y];
	return 0;
}

int DFS1 (int x, int num, int &cbeg, int &cen) {
	used[x] = true;
	int ebeg = beg[x], een = en[x];
	for (int i = 0; i < int (edge[x].size ()); ++i)
		if (!used[edge[x][i].first])
			DFS1 (edge[x][i].first, edge[x][i].second, ebeg, een);
	res[num] = een - ebeg;
	assert (res[num] >= 0);
	cbeg += ebeg;
	cen += een;
	return 0;
}

int main () {
	scanf ("%d", &n);
	for (int i = 1; i <= n; ++i)
		edge[i].clear ();
	for (int i = 1; i < n; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		edge[a].push_back (make_pair (b, i));
		edge[b].push_back (make_pair (a, i));
	}
	memset (used, 0, sizeof (used));
	DFS (1, 0);
	scanf ("%d", &k);
	for (int i = 0; i < k; ++i) {
		int a, b;
		scanf ("%d%d", &a, &b);
		int l_c_a = lca (a, b);
		//printf ("a b lca %d %d %d\n", a, b, l_c_a);
		add (l_c_a, a);
		add (l_c_a, b);
	}
	int abeg = 0, aen = 0;
	memset (used, 0, sizeof (used));
	DFS1 (1, 0, abeg, aen);
	for (int i = 1; i < n; ++i)
		printf ("%d ", res[i]);
	printf ("\n");
	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[Find(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);
        if(u==v) continue;
        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;
}
/*
7
1 2
1 3
2 4
2 5
3 6
3 7

4
6 3
6 1
6 5
1 1
*/


#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;
}