#include <bits/stdc++.h>   using namespace std;   const int N = 111111;   int last[3 * N], pre[3 * N], v[3 * N], cnt[3 * N], cur = 0;   inline void add(int a, int b) {     pre[cur] = last[a];     v[cur] = b;     last[a] = cur;     cur++;   }   set<int>* who[N];   inline set<int>* merge(set<int>*& a, set<int>*& b) {     if (a->size() < b->size()) {       return merge(b, a);     } else {       for (set<int>::iterator it = b->begin(); it != b->end(); it++) {         if (a->find(-*it) != a->end()) {           a->erase(-*it);         } else {           a->insert(*it);         }       }       b->clear();       return a;     }   }   int used[N];   void dfs(int u) {     used[u] = true;     for (int i = last[u]; i >= 0; i = pre[i])       if (!used[v[i]]) {         dfs(v[i]);         cnt[i ^ 1] = cnt[i] = who[v[i]]->size();         who[u] = merge(who[u], who[v[i]]);       }   }   set<int>* mem[N];   int main() {     memset(last, -1, sizeof(last));     int n;     scanf( %d , &n);     for (int i = (0); i <= ((n - 1) - 1); i++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       add(u, v);       add(v, u);     }     for (int i = (0); i <= ((n)-1); i++) mem[i] = who[i] = new set<int>();     int k;     scanf( %d , &k);     for (int i = (1); i <= ((k)); i++) {       int u, v;       scanf( %d%d , &u, &v);       u--;       v--;       if (u != v) {         who[u]->insert(i);         who[v]->insert(-i);       }     }     dfs(0);     for (int i = 0; i < cur; i += 2) {       if (i) printf(   );       printf( %d , cnt[i]);     }     puts(  );     for (int i = (0); i <= ((n)-1); i++) delete (mem[i]);     return 0;   }   