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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

    // precompute L
    DFS(root, 0);

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

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

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

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

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

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

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

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

    return 0;
}


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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

    // precompute L
    DFS(root, 0);

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

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

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

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

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

    if(n > 50000)
    assert(0);

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

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

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

    return 0;
}


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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

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

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

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

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

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

    if(n > 50000)
    assert(0);

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

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

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

    return 0;
}


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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

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

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

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

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

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

    if(n > 50000)
    assert(0);

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

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

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

    return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define sz(x) ((int)(x).size())
#define TASKNAME "std"

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<int, int> pii;

class Dsu {
  vi par, ss, ans;

  int get(int x) { return par[x] == x ? x : par[x] = get(par[x]); }
  public:
  Dsu(int n = 0) : par(n), ss(n, 1), ans(n) {
    for (int i = 0; i < n; i++)
      par[i] = ans[i] = i;
  }
  int getAns(int x) { return ans[get(x)]; }
  void mergeTo(int a, int b) {
    a = get(a); b = get(b);
    if (a == b) return;

    int nv = ans[b];
    if (ss[a] > ss[b]) swap(a, b);
    par[a] = b;
    ss[b] += ss[a];
    ans[b] = nv;
  }
};

vb was;
vvi es, esid;

vvi rqs, rqids;
vi rans;

Dsu dsu;

void dfs(int v) {
  was[v] = true;
  for (int i = 0; i < sz(rqs[v]); i++) {
    int b = rqs[v][i];
    if (!was[b]) continue;

    int id = rqids[v][i];
    assert(rans[id] < 0);
    rans[id] = dsu.getAns(b);
  }

  for (int i = 0; i < sz(es[v]); i++) {
    int b = es[v][i];
    if (was[b]) continue;
    dfs(b);
    dsu.mergeTo(b, v);
  }
}

vi eans;
vi ds;
int dfs2(int v) {
  was[v] = true;
  int res = ds[v];
  for (int i = 0; i < sz(es[v]); i++) {
    int b = es[v][i];
    if (was[b]) continue;
    int cres = dfs2(b);
    eans[esid[v][i]] = cres;
    res += cres;
  }
  return res;
}

int main() {
  #ifdef DEBUG
  freopen(TASKNAME ".in", "r", stdin);
  freopen(TASKNAME ".out", "w", stdout);
  #endif

  int n;
  while (scanf("%d", &n) >= 1) {
    es = vvi(n); esid = vvi(n);
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      es[a].pb(b); esid[a].pb(i);
      es[b].pb(a); esid[b].pb(i);
    }

    int k;
    scanf("%d", &k);
    rqs = vvi(n);
    rqids = vvi(n);

    vector<pii> rls;
    for (int i = 0; i < k; i++) {
      int a, b;
      scanf("%d%d", &a, &b), a--, b--;
      rls.pb(mp(a, b));
      rqs[a].pb(b); rqids[a].pb(i);
      if (a != b) {
        rqs[b].pb(a); rqids[b].pb(i);
      }
    }

    was = vb(n, false);
    rans = vi(k, -1);
    dsu = Dsu(n);
    dfs(0);

    ds = vi(n, 0);
    for (int i = 0; i < k; i++) {
      ds[rls[i].first]++;
      ds[rls[i].second]++;
      ds[rans[i]] -= 2;
    }

    eans = vi(n - 1, 0);
    was = vb(n, false);
    dfs2(0);
    for (int i = 0; i <  n - 1; i++)
      printf("%d%c", eans[i], "\n "[i + 1 < n - 1]);
  }
  return 0;
}


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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

    // precompute L
    DFS(root, 0);

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

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

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

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

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

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

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

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

    return 0;
}


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

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

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

#define pr16

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

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

int n, logn, root;

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

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

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

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

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

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

    if(p == q)
  return p;

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

    return A[p][0];
}

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

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

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

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

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

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

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

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

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

    if(n > 50000)
    assert(0);

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

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

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

    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
#define l2(x) bin(0,30,x,-1)
typedef long long ll;

int n,q;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > obilazak;
int put[MAXN];
int nzp[MAXN];
int res[MAXN];
pair<int,int> spars[MAXN][30];
int pojava[MAXN];
int bin(int l,int d,int x,int res){
    if(l>d)return res;
    int mid=(l+d)/2;
    if(x>=1<<mid)return bin(mid+1,d,x,mid);
    return bin(l,mid-1,x,res);

}
void gradim(int t,int o,int h){
    obilazak.push_back(make_pair(h,t));
    pojava[t]=obilazak.size()-1;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        gradim(niz[t][i].first,t,h+1);
        obilazak.push_back(make_pair(h,t));
    }

}
void sparsinit(){
    gradim(1,-1,0);
    for(int i=0;i<obilazak.size();i++){
        spars[i][0]=obilazak[i];

    }
    int j=1;
    while((1<<j)<obilazak.size()){
        for(int i=0;i<=obilazak.size()-(1<<j);i++){
            spars[i][j]=min(spars[i][j-1],spars[i+(1<<(j-1))][j-1]);
        }
        j++;

    }

}
int lca(int a,int b){
    int l=min(pojava[a],pojava[b]);
    int d=max(pojava[a],pojava[b]);
    int k=l2(d-l+1);

    if(spars[l][k]<spars[d-(1<<k)+1][k])return spars[l][k].second;
    return spars[d-(1<<k)+1][k].second;

}

int dfs(int t,int o){
    int s=0;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        int x=dfs(niz[t][i].first,t);
        res[niz[t][i].second]=x;
        s+=x;
    }
    return s+put[t]-2*nzp[t];

}

int main(){
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        niz[t1].push_back(make_pair(t2,i));
        niz[t2].push_back(make_pair(t1,i));
    }
    sparsinit();

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        put[t1]++;
        put[t2]++;
        nzp[lca(t1,t2)]++;
    }
    //dfs(1,-1);
    for(int i=1;i<n;i++){
        printf("%d ",res[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
#define l2(x) bin(0,30,x,-1)
typedef long long ll;

int n,q;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > obilazak;
int put[MAXN];
int nzp[MAXN];
int res[MAXN];
pair<int,int> spars[MAXN][30];
int pojava[MAXN];
int bin(int l,int d,int x,int res){
    if(l>d)return res;
    int mid=(l+d)/2;
    if(x>=1<<mid)return bin(mid+1,d,x,mid);
    return bin(l,mid-1,x,res);

}
void gradim(int t,int o,int h){
    obilazak.push_back(make_pair(h,t));
    pojava[t]=obilazak.size()-1;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        gradim(niz[t][i].first,t,h+1);
        obilazak.push_back(make_pair(h,t));
    }

}
void sparsinit(){
    gradim(1,-1,0);
    for(int i=0;i<obilazak.size();i++){
        spars[i][0]=obilazak[i];

    }
    int j=1;
    while((1<<j)<obilazak.size()){
        for(int i=0;i<=obilazak.size()-(1<<j);i++){
            spars[i][j]=min(spars[i][j-1],spars[i+(1<<(j-1))][j-1]);
        }
        j++;

    }

}
int lca(int a,int b){
    int l=min(pojava[a],pojava[b]);
    int d=max(pojava[a],pojava[b]);
    int k=l2(d-l+1);

    if(spars[l][k]<spars[d-(1<<k)+1][k])return spars[l][k].second;
    return spars[d-(1<<k)+1][k].second;

}

int dfs(int t,int o){
    int s=0;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        int x=dfs(niz[t][i].first,t);
        res[niz[t][i].second]=x;
        s+=x;
    }
    return s+put[t]-2*nzp[t];

}

int main(){
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        niz[t1].push_back(make_pair(t2,i));
        niz[t2].push_back(make_pair(t1,i));
    }
    sparsinit();

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        put[t1]++;
        put[t2]++;
        nzp[lca(t1,t2)]++;
    }
    dfs(1,-1);
    for(int i=1;i<n;i++){
        printf("%d ",res[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
#define l2(x) bin(0,30,x,-1)
typedef long long ll;

int n,q;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > obilazak;
int put[MAXN];
int nzp[MAXN];
int res[MAXN];
pair<int,int> spars[MAXN][30];
int pojava[MAXN];
int bin(int l,int d,int x,int res){
    if(l>d)return res;
    int mid=(l+d)/2;
    if(x>=1<<mid)return bin(mid+1,d,x,mid);
    return bin(l,mid-1,x,res);

}
void gradim(int t,int o,int h){
    obilazak.push_back(make_pair(h,t));
    pojava[t]=obilazak.size()-1;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        gradim(niz[t][i].first,t,h+1);
        obilazak.push_back(make_pair(h,t));
    }

}
void sparsinit(){
    gradim(1,-1,0);
    for(int i=0;i<obilazak.size();i++){
        spars[i][0]=obilazak[i];

    }
    int j=1;
    while((1<<j)<obilazak.size() && j<30){
        for(int i=0;i<=obilazak.size()-(1<<j);i++){
            spars[i][j]=min(spars[i][j-1],spars[i+(1<<(j-1))][j-1]);
        }
        j++;

    }

}
int lca(int a,int b){
    int l=min(pojava[a],pojava[b]);
    int d=max(pojava[a],pojava[b]);
    int k=l2(d-l+1);
    if(k==-1){
        printf("jeff");exit(0);
    }
    if(spars[l][k]<spars[d-(1<<k)+1][k])return spars[l][k].second;
    return spars[d-(1<<k)+1][k].second;

}

int dfs(int t,int o){
    int s=0;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        int x=dfs(niz[t][i].first,t);
        res[niz[t][i].second]=x;
        s+=x;
    }
    return s+put[t]-2*nzp[t];

}

int main(){
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        niz[t1].push_back(make_pair(t2,i));
        niz[t2].push_back(make_pair(t1,i));
    }
    sparsinit();

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        put[t1]++;
        put[t2]++;
        nzp[lca(t1,t2)]++;
    }
    dfs(1,-1);
    for(int i=1;i<n;i++){
        printf("%d ",res[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
#define l2(x) bin(0,30,x,-1)
typedef long long ll;

int n,q;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > obilazak;
int put[MAXN];
int nzp[MAXN];
int res[MAXN];
pair<int,int> spars[MAXN][30];
int pojava[MAXN];
int bin(int l,int d,int x,int res){
    if(l>d)return res;
    int mid=(l+d)/2;
    if(x>=1<<mid)return bin(mid+1,d,x,mid);
    return bin(l,mid-1,x,res);

}
void gradim(int t,int o,int h){
    obilazak.push_back(make_pair(h,t));
    pojava[t]=obilazak.size()-1;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        gradim(niz[t][i].first,t,h+1);
        obilazak.push_back(make_pair(h,t));
    }

}
void sparsinit(){
    gradim(1,-1,0);
    for(int i=0;i<obilazak.size();i++){
        spars[i][0]=obilazak[i];

    }
    int j=1;
    while((1<<j)<obilazak.size()){
        for(int i=0;i<=obilazak.size()-(1<<j);i++){
            spars[i][j]=min(spars[i][j-1],spars[i+(1<<(j-1))][j-1]);
        }
        j++;

    }

}
int lca(int a,int b){
    int l=min(pojava[a],pojava[b]);
    int d=max(pojava[a],pojava[b]);
    int k=l2(d-l+1);

    if(spars[l][k]<spars[d-(1<<k)+1][k])return spars[l][k].second;
    return spars[d-(1<<k)+1][k].second;

}

int dfs(int t,int o){
    int s=0;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        int x=dfs(niz[t][i].first,t);
        res[niz[t][i].second]=x;
        s+=x;
    }
    return s+put[t]-2*nzp[t];

}

int main(){
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        niz[t1].push_back(make_pair(t2,i));
        niz[t2].push_back(make_pair(t1,i));
    }
    sparsinit();

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        put[t1]++;
        put[t2]++;
        nzp[lca(t1,t2)]++;
    }
    if(n<100)dfs(1,-1);
    for(int i=1;i<n;i++){
        printf("%d ",res[i]);
    }
    return 0;
}


#include <bits/stdc++.h>
#define MAXN 100005
using namespace std;
#define l2(x) bin(0,30,x,-1)
typedef long long ll;

int n,q;
vector<pair<int,int> > niz[MAXN];
vector<pair<int,int> > obilazak;
int put[MAXN];
int nzp[MAXN];
int res[MAXN];
pair<int,int> spars[MAXN+MAXN+5][30];
int pojava[MAXN];
int bin(int l,int d,int x,int res){
    if(l>d)return res;
    int mid=(l+d)/2;
    if(x>=1<<mid)return bin(mid+1,d,x,mid);
    return bin(l,mid-1,x,res);

}
void gradim(int t,int o,int h){
    obilazak.push_back(make_pair(h,t));
    pojava[t]=obilazak.size()-1;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        gradim(niz[t][i].first,t,h+1);
        obilazak.push_back(make_pair(h,t));
    }

}
void sparsinit(){
    gradim(1,-1,0);
    for(int i=0;i<obilazak.size();i++){
        spars[i][0]=obilazak[i];

    }
    int j=1;
    while((1<<j)<obilazak.size() && j<30){
        for(int i=0;i<=obilazak.size()-(1<<j);i++){
            spars[i][j]=min(spars[i][j-1],spars[i+(1<<(j-1))][j-1]);
        }
        j++;

    }

}
int lca(int a,int b){
    int l=min(pojava[a],pojava[b]);
    int d=max(pojava[a],pojava[b]);
    int k=l2(d-l+1);
    if(spars[l][k]<spars[d-(1<<k)+1][k])return spars[l][k].second;
    return spars[d-(1<<k)+1][k].second;

}

int dfs(int t,int o){
    int s=0;
    for(int i=0;i<niz[t].size();i++){
        if(niz[t][i].first==o)continue;
        int x=dfs(niz[t][i].first,t);
        res[niz[t][i].second]=x;
        s+=x;
    }
    return s+put[t]-2*nzp[t];

}

int main(){
    scanf("%d", &n);
    for(int i=1;i<n;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        niz[t1].push_back(make_pair(t2,i));
        niz[t2].push_back(make_pair(t1,i));
    }
    sparsinit();

    scanf("%d", &q);
    for(int i=1;i<=q;i++){
        int t1,t2;
        scanf("%d %d", &t1, &t2);
        put[t1]++;
        put[t2]++;
        nzp[lca(t1,t2)]++;
    }
    dfs(1,-1);
    for(int i=1;i<n;i++){
        printf("%d ",res[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;
    scanf("%d" , &n);
    for(int i = 1 ; i < n ; i++){
        int fi , se;
        scanf("%d" , &fi);
        scanf("%d" , &se);
        V[fi].pb(se);
        V[se].pb(fi);
        mp[pii(fi , se)] = i;
        mp[pii(se , fi)] = i;
    }

    dfs(1 , 0);

    int q;
    scanf("%d" , &q);
    for(int i = 1 ; i <= q ; i++){
        int x , y;
        scanf("%d" , &x);
        scanf("%d" , &y);
        S[x]++;
        S[y]++;
        S[LCA(x , y)] -= 2;
    }

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


//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(const int &x , const 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(const int &x , const int &par , const 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()
{
    int n;
    scanf("%d" , &n);
    for(int i = 1 ; i < n ; i++){
        int fi , se;
        scanf("%d" , &fi);
        scanf("%d" , &se);
        V[fi].pb(se);
        V[se].pb(fi);
        mp[pii(fi , se)] = i;
        mp[pii(se , fi)] = i;
    }

    dfs(1 , 0);

    int q;
    scanf("%d" , &q);
    for(int i = 1 ; i <= q ; i++){
        int x , y;
        scanf("%d" , &x);
        scanf("%d" , &y);
        S[x]++;
        S[y]++;
        S[LCA(x , y)] -= 2;
    }

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


//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 = 2 ; i+1 ; i--){
        if(High[Par[x][i]] >= High[y])
            x = Par[x][i];
    }

    if(x == y)
        return x;
    for(int i = maxlog - 1 ; i+1 ; 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] << " ";
}


import java.util.Scanner;
import java.util.HashMap;
import java.util.*;

public class codeforces{

public static void main(String args[]){

	HashMap<Integer,Integer> map=new HashMap<Integer,Integer> ();

	Scanner input=new Scanner(System.in);

	int n=input.nextInt();

	int[][]nums=new int[n][n];

	for(int i=0;i<n;i++)
	for(int j=0;j<n;j++) nums[i][j]=input.nextInt();

	    int result[]=new int[n+1];

	    int contor=0;

	    if (n==1) System.out.println(1);

	    else{

	    for(int i=0;i<n;i++){

	        int x=0;
	        for(int j=0;j<n;j++) if(nums[i][j]==1 || nums[i][j]==3 )
	                x=1;

	                if(x==0) {contor++;result[contor]=i+1;
	                   // System.out.println
	                  //  ("contor="+contor+"  nums "
	                  //  +result[contor]+"  i="+i);

	                }
	    }

	    System.out.println(contor);

	    for(int i=0;i<n;i++)
	   { if(result[i]>0)
	    System.out.print(result[i]+" ");}}

			}

		}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class contest {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        TreeSet<Integer> cars = creator(N);
        for (int i = 0; i < N; i++) {
            String[] actualLine = br.readLine().split(" ");
            for (int j = 0; j < N; j++) {
                int actualNum = Integer.parseInt(actualLine[j]);
                if (actualNum==1){
                    cars.remove(i+1);
                }
                else if (actualNum == 2) cars.remove(j+1);
                else if (actualNum==3){
                    cars.remove(i+1);
                    cars.remove(j+1);
                }
            }
        }
        System.out.println(cars.size());
        if (cars.size()>0){
            String resp = "";
            for (int num : cars) resp+=num+" ";
            System.out.println(resp.substring(0, resp.length()-1));
        }

    }

    private static TreeSet<Integer> creator(int n) {
        TreeSet<Integer> resp = new TreeSet<Integer>();
        for (int i = 1; i <=n; i++) {
            resp.add(i);
        }
        return resp;
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.TreeSet;

public class contest {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int N = Integer.parseInt(br.readLine());
        TreeSet<Integer> cars = creator(N);
        for (int i = 0; i < N; i++) {
            String[] actualLine = br.readLine().split(" ");
            for (int j = 0; j < N; j++) {
                int actualNum = Integer.parseInt(actualLine[j]);
                if (actualNum==1){
                    cars.remove(i+1);
                }
                else if (actualNum == 2) cars.remove(j+1);
                else if (actualNum==3){
                    cars.remove(i+1);
                    cars.remove(j+1);
                }
            }
        }
        System.out.println(cars.size());
        String resp = "";
        for (int num : cars) resp+=num+" ";
        System.out.println(resp.substring(0, resp.length()-1));

    }

    private static TreeSet<Integer> creator(int n) {
        TreeSet<Integer> resp = new TreeSet<Integer>();
        for (int i = 1; i <=n; i++) {
            resp.add(i);
        }
        return resp;
    }

}


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemA{

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int cars  = in.nextInt();
        int answer = 0;
        ArrayList<Integer> good = new ArrayList<Integer>();
        for(int i =0;i<cars;i++){
            boolean g = true;
            for(int j=0;j<cars;j++){
                int col = in.nextInt();
                if(col==1 || col ==3)
                    g=false;
                }

            if(g){
                answer++;
                good.add(i+1);
            }
        }
        out.println(answer);
        String s = "";
        for(int i = 0;i<good.size();i++){
            out.print(good.get(i));
            if(i<good.size()-1)
                out.print(" ");
        }
        out.close();
    }

    //-----------PrintWriter for faster output---------------------------------
       public static PrintWriter out;

       //-----------MyScanner class for faster input----------
       public static class MyScanner {
          BufferedReader br;
          StringTokenizer st;

          public MyScanner() {
             br = new BufferedReader(new InputStreamReader(System.in));
          }

          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }

          int nextInt() {
              return Integer.parseInt(next());
          }

          long nextLong() {
              return Long.parseLong(next());
          }

          double nextDouble() {
              return Double.parseDouble(next());
          }

          String nextLine(){
              String str = "";
          try {
             str = br.readLine();
          } catch (IOException e) {
             e.printStackTrace();
          }
          return str;
          }

       }
       //--------------------------------------------------------
    }


import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.StringTokenizer;

public class ProblemA{

    public static void main(String[] args) {
        MyScanner in = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int cars  = in.nextInt();
        int answer = 0;
        ArrayList<Integer> good = new ArrayList<Integer>();
        for(int i =0;i<cars;i++){
            boolean g = true;
            for(int j=0;j<cars && g;j++){
                int col = in.nextInt();
                if(col==1 || col ==3)
                    g=false;
                }

            if(g){
                answer++;
                good.add(i+1);
            }
        }
        out.println(answer);
        String s = "";
        for(int i = 0;i<good.size();i++){
            out.print(good.get(i));
            if(i<good.size()-1)
                out.print(" ");
        }
        out.close();
    }

    //-----------PrintWriter for faster output---------------------------------
       public static PrintWriter out;

       //-----------MyScanner class for faster input----------
       public static class MyScanner {
          BufferedReader br;
          StringTokenizer st;

          public MyScanner() {
             br = new BufferedReader(new InputStreamReader(System.in));
          }

          String next() {
              while (st == null || !st.hasMoreElements()) {
                  try {
                      st = new StringTokenizer(br.readLine());
                  } catch (IOException e) {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }

          int nextInt() {
              return Integer.parseInt(next());
          }

          long nextLong() {
              return Long.parseLong(next());
          }

          double nextDouble() {
              return Double.parseDouble(next());
          }

          String nextLine(){
              String str = "";
          try {
             str = br.readLine();
          } catch (IOException e) {
             e.printStackTrace();
          }
          return str;
          }

       }
       //--------------------------------------------------------
    }


import java.util.Scanner;
import java.io.PrintWriter;

//import java.util.Arrays;
//import java.lang.Comparable;
//import java.util.HashMap;
import java.lang.StringBuffer;

public class Main {

    static Scanner in = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static StringBuffer sb = new StringBuffer();

    public static void main(String[] args) {
        int n = in.nextInt(), t = 0;
        for(int i = 0; i < n; i++) {
            boolean b = true;
            for(int j = 0; j < n; j++)
                if(in.nextInt() % 2 == 1)
                    b = false;
            if(b) {
                sb.append((i + 1) + " ");
                t++;
            }
        }
        out.println(t);
        out.print(sb);
        out.close();
    }
}


import java.util.Scanner;
import java.io.PrintWriter;

//import java.util.Arrays;
//import java.lang.Comparable;
//import java.util.HashMap;
import java.lang.StringBuffer;

public class Main {

    static Scanner in = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);
    static StringBuffer sb = new StringBuffer();

    public static void main(String[] args) {
        int n = in.nextInt(), t = n;
        for(int i = 0; i < n; i++) {
            boolean b = true;
            for(int j = 0; j < n; j++) {
                if(in.nextInt() % 2 == 1) {
                    t--;
                    j = n;
                    b = false;
                }
            }
            if(b)
                sb.append(i + 1 + " ");
        }
        out.println(t);
        out.print(sb);
        out.close();
    }
}


package code;

import java.util.Scanner;

public class ToyCars {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[][] = new int[n][n];
		for (int a_i = 0; a_i < n; a_i++) {
			for (int a_j = 0; a_j < n; a_j++) {
				a[a_i][a_j] = in.nextInt();
			}
		}

		int result;
		int[] score = new int[n];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				result = a[i][j];

				if (result == 1) {
					score[i] = -1;
				} else if (result == 2) {
					score[j] = -1;
				} else if (result == 3) {
					score[i] = -1;
					score[j] = -1;
				}
			}
		}

		int sum = 0;
		String split = "";
		StringBuilder cars = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (score[i] != -1) {
				sum++;
				cars.append(split).append(i + 1);
				split = " ";
			}
		}

		System.out.println(sum);
		System.out.println(cars.toString());
	}
}


import java.util.Scanner;

public class ToyCars {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[][] = new int[n][n];
		for (int a_i = 0; a_i < n; a_i++) {
			for (int a_j = 0; a_j < n; a_j++) {
				a[a_i][a_j] = in.nextInt();
			}
		}

		int result;
		int[] score = new int[n];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				result = a[i][j];

				if (result == 1) {
					score[i] = -1;
				} else if (result == 2) {
					score[j] = -1;
				} else if (result == 3) {
					score[i] = -1;
					score[j] = -1;
				}
			}
		}

		int sum = 0;
		String split = "";
		StringBuilder cars = new StringBuilder();
		for (int i = 0; i < n; i++) {
			if (score[i] != -1) {
				sum++;
				cars.append(split).append(i + 1);
				split = " ";
			}
		}

		System.out.println(sum);
		System.out.println(cars.toString());
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class PA {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0;i<n;i++){
			for (int j = 0;j<n;j++){
				a[i][j] = sc.nextInt();
			}
		}
		int[] a2 = new int[n];
		for (int i = 0;i<n;i++){
			for (int j = i+1;j<n;j++){
				if (a[i][j] == 1){
					a2[i]=1;
				}
				else if (a[i][j] == 2){
					a2[j]=1;
				}
				else if (a[i][j] == 3){
					a2[i]=1;
					a2[j]=1;
				}
			}
		}
		int sum = 0;
		for (int i : a2)
		    sum += i;
		System.out.println(n-sum);
	}
}


import java.util.Arrays;
import java.util.Scanner;

public class PA {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0;i<n;i++){
			for (int j = 0;j<n;j++){
				a[i][j] = sc.nextInt();
			}
		}
		int[] a2 = new int[n];
		for (int i = 0;i<n;i++){
			for (int j = i+1;j<n;j++){
				if (a[i][j] == 1){
					a2[i]=1;
				}
				else if (a[i][j] == 2){
					a2[j]=1;
				}
				else if (a[i][j] == 3){
					a2[i]=1;
					a2[j]=1;
				}
			}
		}
		int sum = 0;
		String res = "";
		for (int i = 0;i<n;i++){
			sum += a2[i];
			if (a2[i]==0) res+=i+1+" ";
		}

		System.out.println(n-sum);
		if (n!=sum){
			System.out.println(res.substring(0, res.length()-1));
		}
	}
}


import java.util.Scanner;

public class PA {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] a = new int[n][n];
		for (int i = 0;i<n;i++){
			for (int j = 0;j<n;j++){
				a[i][j] = sc.nextInt();
			}
		}
		int[] a2 = new int[n];
		for (int i = 1;i<n;i++){
			for (int j = i;j<n;j++){
				if (a[i][j] == 1){
					a2[i]=1;
				}
				else if (a[i][j] == 2){
					a2[j]=1;
				}
				else if (a[i][j] == 3){
					a2[i]=1;
					a2[j]=1;
				}
			}
		}
		int sum = 0;
		for (int i : a2)
		    sum += i;
		System.out.println(n-sum);
	}
}


// http://codeforces.com/problemset/problem/545/A

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);

		int n = read.nextInt();

		List<Integer> goodCarIndices = new ArrayList<Integer>();
		for (int i = 0; i < n; ++i) {
			boolean isGoodCar = true;
			for (int j = 0; j < n; ++j) {
				int collisionResult = read.nextInt();
				if (collisionResult == 1 || collisionResult == 3) {
					isGoodCar = false;
				}
			}
			if (isGoodCar) {
				goodCarIndices.add(i+1);
			}
		}

		System.out.println( goodCarIndices.size() );
		for (Integer carIndex : goodCarIndices) {
			System.out.print(carIndex + " ");
		}

		// Close scanner
		read.close();
	}

}


// http://codeforces.com/problemset/problem/545/A

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Solution {

	public static void main(String[] args) {
		Scanner read = new Scanner(System.in);

		int n = read.nextInt();

		int numberOfGoodCars = 0;
		List<Integer> goodCarIndices = new ArrayList<Integer>();

		for (int i = 0; i < n; ++i) {
			boolean isGoodCar = true;
			for (int j = 0; j < n; ++j) {
				int collisionResult = read.nextInt();
				if (collisionResult == 1 || collisionResult == 3) {
					isGoodCar = false;
					break;
				}
			}
			if (isGoodCar) {
				numberOfGoodCars++;
				goodCarIndices.add(i+1);
			}
		}

		System.out.println(numberOfGoodCars);
		for (Integer carIndex : goodCarIndices) {
			System.out.print(carIndex + " ");
		}

		// Close scanner
		read.close();
	}

}


import java.util.Scanner;

public class PROBLEM545A {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		boolean flag = true;
		int count = 0;
		String pass = "";

		int array[][] = new int[n][n];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				array[i][j] = scanner.nextInt();
				if (array[i][j] == 1 || array[i][j] == 3) flag = false;
			}

			if (flag) { pass += (i+1) + " "; count++; }
			else flag = true;
		}

		System.out.println(count);
		if (!pass.equals("")) System.out.println(pass.trim());
	}
}


import java.util.Scanner;

public class PROBLEM545A {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);

		int n = scanner.nextInt();
		String pass = "";
		boolean flag = true;
		int count = 0;

		for (int num = 0, i = 1; num < n*n; num++) {
			int cell = scanner.nextInt();
			if (cell == 1 || cell == 3) flag = false;

			if (num > 0 && num % n == 0) {
				if (flag) { pass += i + " "; count++; }
				else flag = true;

				i++;
			}
		}

		System.out.println(count);
		if (!pass.equals("")) System.out.println(pass.trim());
	}
}


import java.util.Scanner;

public class Toy_Cars {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        boolean good[] = new boolean[n];
        for(int i=0;i<n;i++){
            good[i]=true;
        }
        for (int i = 0; i < n; i++) {
            if (good[i] != false) {
                for (int j = 0; j < n; j++) {
                    int x = s.nextInt();
                    if (x == 1 || x == 3) {
                        good[i] = false;
                        if (x == 3) {
                            good[j] = false;
                        }
                        break;
                    }
                }
            }
        }

        String indices = "";
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (good[i]) {
                indices = indices + (i + 1) + " ";
                count++;
            }
        }
        System.out.println(count + "\n" + indices);
    }
}


import java.util.Scanner;

public class Toy_Cars {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        boolean good[] = new boolean[n];
        for(int i=0;i<n;i++){
            good[i]=true;
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                int x = s.nextInt();
                if(x==1||x==3){
                    good[i]=false;
                    break;
                }
            }
        }
        String indices="";
        int count=0;
        for(int i=0;i<n;i++){
            if(good[i]){
                indices=indices+(i+1)+" ";
                count++;
            }
        }
        System.out.println(count+"\n"+indices);
    }
}


import java.util.Scanner;

public class Toy_Cars {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        boolean good[] = new boolean[n];

        for (int i = 0; i < n; i++) {
            good[i] = true;
            for (int j = 0; j < n; j++) {
                int x = s.nextInt();
                if(x==1||x==3){
                    good[i]=false;
                }
            }
        }
        String indices="";
        int count=0;
        for(int i=0;i<n;i++){
            if(good[i]){
                indices=indices+(i+1)+" ";
                count++;
            }
        }
        System.out.println(count+"\n"+indices);
    }
}


import java.util.Scanner;

public class Toy_Cars {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        boolean good[] = new boolean[n];
        for(int i=0;i<n;i++){
            good[i]=true;
        }
        for (int i = 0; i < n; i++) {
            if (good[i] != false) {
                for (int j = 0; j < n; j++) {
                    int x = s.nextInt();
                    if (x == 1 || x == 3) {
                        good[i] = false;
                        if (x == 3) {
                            good[j] = false;
                        }
                    }
                }
            }
        }

        String indices = "";
        int count = 0;
        for (int i = 0; i < n; i++) {
            if (good[i]) {
                indices = indices + (i + 1) + " ";
                count++;
            }
        }
        System.out.println(count + "\n" + indices);
    }
}


import java.util.Scanner;

public class Toy_Cars {

    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int x;
        boolean good[] = new boolean[n];

        for (int i = 0; i < n; i++) {
            good[i] = true;
            for (int j = 0; j < n; j++) {
                x = s.nextInt();
                if(x==1||x==3){
                    good[i]=false;
                }
            }
        }
        String indices="";
        int count=0;
        for(int i=0;i<n;i++){
            if(good[i]){
                indices=indices+(i+1)+" ";
                count++;
            }
        }
        System.out.println(count+"\n"+indices);
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Toy_Cars {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        try {
            int n, x;
            String in[];
            n = Integer.parseInt(br.readLine());
            boolean good[] = new boolean[n];

            for (int i = 0; i < n; i++) {
                good[i] = true;
                in = br.readLine().split(" ");
                for (int j = 0; j < n; j++) {
                    x = Integer.parseInt(in[j]);
                    if (x == 1 || x == 3) {
                        good[i] = false;
                    }
                }
            }

            String indices = "";
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (good[i]) {
                    indices = indices + (i + 1) + " ";
                    count++;
                }
            }
            System.out.println(count + "\n" + indices);
        } catch (IOException e) {
        }
    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        a[i][j] = sc.nextInt();
      }
    }
    ArrayList<Integer> list = new ArrayList<>();
    for(int i=0;i<n;i++){
      boolean good = true;
      for(int j=i+1;j<n;j++){
        if(a[i][j]==1 ||a[i][j] == 3 ){
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }

    System.out.println(list.size());
    list.stream().forEach(b -> System.out.print(b + " "));
  }
  }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        a[i][j] = sc.nextInt();
      }
    }
    ArrayList<Integer> list = new ArrayList<>();
    for(int i=0;i<n-1;i++){
      boolean good = true;
      for(int j=i+1;j<n;j++){
        if(a[i][j]==0 ||a[i][j] == 2){

        }else{
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }

    for(int i=n-1;i<n;i++){
      boolean good = true;
      for(int j=0;j<n-1;j++){
        if(a[i][j]==0 ||a[i][j] == 2){

        }else{
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }
    System.out.println(list.size());
    list.stream().forEach(b -> System.out.print(b + " "));
  }
  }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        a[i][j] = sc.nextInt();
      }
    }
    ArrayList<Integer> list = new ArrayList<>();
    for(int i=0;i<n;i++){
      boolean good = true;
      for(int j=i+1;j<n;j++){
        if(a[i][j]==0 ||a[i][j] == 2 || a[i][j]!=-1){

        }else{
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }

    System.out.println(list.size());
    list.stream().forEach(b -> System.out.print(b + " "));
  }
  }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        a[i][j] = sc.nextInt();
      }
    }
    ArrayList<Integer> list = new ArrayList<>();
    for(int i=0;i<n-1;i++){
      boolean good = true;
      for(int j=i+1;j<n;j++){
        if(a[i][j]==0 ||a[i][j] == 2){

        }else{
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }

    for(int i=n-1;i<n;i++){
      boolean good = true;
      for(int j=0;j<n-1;j++){
        if(a[i][j]==0 ||a[i][j] == 2){

        }else{
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }
    if(list.size() > 0){
      list.stream().forEach(b -> System.out.print(b + " "));
    }else{
      System.out.println(0);
    }

  }
  }


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

public class Main {

  public static void main(String args[])
  {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[][] a = new int[n][n];
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        a[i][j] = sc.nextInt();
      }
    }
    ArrayList<Integer> list = new ArrayList<>();
    for(int i=0;i<n;i++){
      boolean good = true;
      for(int j=0;j<n;j++){
        if(a[i][j]==1 ||a[i][j] == 3 ){
          good = false;
          break;
        }
      }
      if(good){
        list.add(i+1);
      }
    }

    System.out.println(list.size());
    list.stream().forEach(b -> System.out.print(b + " "));
  }
  }


import java.util.Scanner;

public class Toys{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        int numCars = scan.nextInt();

        boolean[] cars = new boolean[numCars];

        for(int i=0;i<numCars;i++){
            cars[i] = true;
        }

        for(int i=0;i<numCars;i++){
            for(int j=0;j<numCars;j++){
                int result = scan.nextInt();
                if(result == 1){
                    cars[i] = false;
                }else if(result == 2){
                    cars[j] = false;
                }else if(result == 3){
                    cars[i] = false;
                    cars[j] = false;
                }
            }
        }

        int numGoodCars = 0;

        for(int i=0;i<cars.length;i++){
            if(cars[i]){
                numGoodCars++;
            }
        }

        System.out.println(numGoodCars);

        for(int i=0;i<cars.length;i++){
            if(cars[i]){
                System.out.print((i+1) +" ");
            }
        }

    }
}


import java.util.Scanner;

public class Toys{
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);

        int numCars = scan.nextInt();

        boolean[] cars = new boolean[numCars];

        for(int i=0;i<numCars;i++){
            cars[i] = true;
        }

        for(int i=0;i<numCars;i++){
            for(int j=0;j<numCars;j++){
                int result = scan.nextInt();
                if(result == 1){
                    cars[i] = false;
                }else if(result == 2){
                    cars[j] = false;
                }else if(result == 3){
                    cars[i] = false;
                    cars[j] == false;
                }
            }
        }

        int numGoodCars = 0;

        for(int i=0;i<cars.length;i++){
            if(cars[i]){
                numGoodCars++;
            }
        }

        System.out.println(numGoodCars);

        for(int i=0;i<cars.length;i++){
            if(cars[i]){
                System.out.print((i+1) +" ");
            }
        }

    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j>i) {
					if(stats[i][j] == 0) {
						res[i] = 1;
						res[j] = 1;
					} else if(stats[i][j] == 1) {
						res[i] = -1;
						res[j] = 1;
					} else if(stats[i][j] == 2) {
						res[i] = 1;
						res[j] = -1;
					} else {
						res[i] = -1;
						res[j] = -1;
					}
				}
				j += i;
			}
		}

		StringBuilder sb = new StringBuilder();
		boolean ws = true;
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 1) {
				count++;
				if(ws) {
					s = s+""+(i+1);
					ws = false;
				} else
					s = s+" "+(i+1);
			}
		}
		sb.append(count+(s.isEmpty()?"":"\n"));
		sb.append(s);
		System.out.print(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j>i) {
					if(stats[i][j] == 0 && res[i] != -1 && res[j] != -1) {
						res[i] = 1;
						res[j] = 1;
					} else if(stats[i][j] == 1 && res[j] != -1) {
						res[i] = -1;
						res[j] = 1;
					} else if(stats[i][j] == 2 && res[i] != -1) {
						res[i] = 1;
						res[j] = -1;
					} else if(stats[i][j] == 3) {
						res[i] = -1;
						res[j] = -1;
					}
				}
				j += i;
			}
		}

		StringBuilder sb = new StringBuilder();
		boolean ws = true;
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 1) {
				count++;
				if(ws) {
					s = s+""+(i+1);
					ws = false;
				} else
					s = s+" "+(i+1);
			}
		}
		sb.append(count+(s.isEmpty()?"":"\n"));
		sb.append(s);
		System.out.print(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j>i) {
					System.out.println(stats[i][j]);
					if(stats[i][j] == 0 && res[i] != -1 && res[j] != -1) {
						res[i] = 1;
						res[j] = 1;
					} else if(stats[i][j] == 1 && res[j] != -1) {
						res[i] = -1;
						res[j] = 1;
					} else if(stats[i][j] == 2 && res[i] != -1) {
						res[i] = 1;
						res[j] = -1;
					} else if(stats[i][j] == 3) {
						res[i] = -1;
						res[j] = -1;
					}
				}
				j += i;
			}
		}

		StringBuilder sb = new StringBuilder();
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 1) {
				count++;
				s = s+(i+1)+" ";
			}
		}
		sb.append(count+(s.isEmpty()?"":"\n"));
		sb.append(s);
		System.out.print(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];
		Arrays.fill(res, 0);

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j!=i) {
					if(stats[i][j] == 3) {
						res[i] += 1;
						res[j] += 1;
					} else if(stats[i][j] == 2) {
						res[j] += 1;
					} else if(stats[i][j] == 1) {
						res[i] += 1;
					}
				}
			}
		}

		StringBuilder sb = new StringBuilder();
		boolean ws = true;
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 0) {
				count++;
				if(ws) {
					s = s+""+(i+1);
					ws = false;
				} else
					s = s+" "+(i+1);
			}
		}
		sb.append(count+(s.isEmpty()?"":"\n"));
		sb.append(s);
		System.out.print(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1

6
-1 0 1 2 3 1
0 -1 3 1 2 0
2 3 -1 0 1 3
1 2 0 -1 2 2
3 1 2 1 -1 1
2 0 3 1 2 -1

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j>i) {
					if(stats[i][j] == 0) {
						res[i] = 1;
						res[j] = 1;
					} else if(stats[i][j] == 1) {
						res[i] = -1;
						res[j] = 1;
					} else if(stats[i][j] == 2) {
						res[i] = 1;
						res[j] = -1;
					} else {
						res[i] = -1;
						res[j] = -1;
					}
				}
				j += i;
			}
		}

		StringBuilder sb = new StringBuilder();
		boolean ws = true;
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 1) {
				count++;
				if(ws) {
					s = s+""+(i+1);
					ws = false;
				} else
					s = s+" "+(i+1);
			}
		}
		sb.append(count+"\n");
		sb.append(s);
		System.out.println(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

*/


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int cars = Integer.parseInt(br.readLine().trim());
		int[][] stats = new int[cars][cars];
		int[] res = new int[cars];
		Arrays.fill(res, 0);

		for (int i = 0; i < cars; i++) {
			String[] split = br.readLine().split(" ");
			for (int j = 0; j < split.length; j++) {
				stats[i][j] = Integer.parseInt(split[j].trim());
				if(j>i) {
					if(stats[i][j] == 3) {
						res[i] += 1;
						res[j] += 1;
					} else if(stats[i][j] == 2) {
						res[j] += 1;
					} else if(stats[i][j] == 1) {
						res[i] += 1;
					}
				}
				j += i;
			}
		}

		StringBuilder sb = new StringBuilder();
		boolean ws = true;
		int count = 0;
		String s = "";
		for (int i = 0; i < res.length; i++) {
			if(res[i] == 0) {
				count++;
				if(ws) {
					s = s+""+(i+1);
					ws = false;
				} else
					s = s+" "+(i+1);
			}
		}
		sb.append(count+(s.isEmpty()?"":"\n"));
		sb.append(s);
		System.out.print(sb.toString());
	}
}

/*
3
-1 0 0
0 -1 1
0 2 -1

4
-1 3 3 3
3 -1 3 3
3 3 -1 3
3 3 3 -1

*/


import java.util.*;
public class ToyCar {

    public static void main(String[] args) {

    	Scanner s = new Scanner(System.in);
    	int x = s.nextInt();
    	int y =0;
    	String out = s.nextLine();
    	String[] str = new String [x];
		for (int i=0; i<x; i++){
    		str[i] = (s.nextLine()).replace("-1", "x");
    		if (str[i].contains("1"))
    			x = x;
    		else {
    			y ++;
    			out += i+1 +" ";
    		}
    	}
    	System.out.println(y);
    	System.out.println(out);
    }
}


import java.util.*;
public class ToyCar {

    public static void main(String[] args) {

    	Scanner s = new Scanner(System.in);
    	int x = s.nextInt();
    	int y =0;
    	String out = s.nextLine();
    	String[] str = new String [x];
		for (int i=0; i<x; i++){
    		str[i] = (s.nextLine()).replace("-1", "x");
    		if (str[i].contains("1"))
    			x = x;
    		else {
    			y ++;
    			out += i+1;
    		}
    	}
    	System.out.println(y);
    	System.out.println(out);
    }
}


import java.util.*;
public class ToyCar {

    public static void main(String[] args) {

    	Scanner s = new Scanner(System.in);
    	int x = s.nextInt();
    	int y =0;
    	String out = s.nextLine();
    	String[] str = new String [x];
		for (int i=0; i<x; i++){
    		str[i] = (s.nextLine()).replace("-1", "x");
    		if (str[i].contains("1") || str[i].contains("3"))
    			x = x;
    		else {
    			y ++;
    			out += i+1 +" ";
    		}
    	}
    	System.out.println(y);
    	System.out.println(out);
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Solver {
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        int n = nextInt();
        int a[][]= new int[n][n];
        TreeSet<Integer>ts = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            ts.add(i);
            for (int j = 0; j < n; j++) {
                a[i][j] = nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i][j] == 1)if(ts.contains(i))ts.remove(i);
                else if (a[i][j] == 2)if(ts.contains(j))ts.remove(j);
                else if (a[i][j] == 3){
                    if(ts.contains(i))ts.remove(i);
                    if(ts.contains(j))ts.remove(j);
                }
            }
        }
        pw.println(ts.size());
        for (int x : ts)pw.print((x + 1) + " ");
        pw.close();
    }

    static StringTokenizer st = new StringTokenizer("");
    static BufferedReader br;
    static PrintWriter pw;

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}


import java.io.*;
import java.util.*;

import static java.lang.Math.*;

public class Solver {
    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        pw = new PrintWriter(System.out);
        int n = nextInt();
        int a[][] = new int[n][n];
        TreeSet<Integer> ts = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            ts.add(i);
            for (int j = 0; j < n; j++) {
                a[i][j] = nextInt();
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (a[i][j] == 1) {
                    if (ts.contains(i)) ts.remove(i);
                } else if (a[i][j] == 2) {
                    if (ts.contains(j)) ts.remove(j);
                } else if (a[i][j] == 3) {
                    if (ts.contains(i)) ts.remove(i);
                    if (ts.contains(j)) ts.remove(j);
                }
            }
        }

        pw.println(ts.size());
        for (int x : ts)
            pw.print((x + 1) + " ");
        pw.close();
    }

    static StringTokenizer st = new StringTokenizer("");
    static BufferedReader br;
    static PrintWriter pw;

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }
}


import java.io.*;
import java.util.*;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int T=1,n,i,j=0,k=0;
		long m,l,ans=0l,ans2=0l,ans3=0l,b,c;
		for (int tt=0; tt<T; tt++)
		{
			n=fs.nextInt();
// 			m=fs.nextLong();
			int[][] a=new int[n][n];
			ArrayList<Integer> ar=new ArrayList<>();
			for(i=0;i<n;i++)
			for(j=0;j<n;j++)
			a[i][j]=fs.nextInt();
		    outer:for(i=0;i<n;i++)
			{
			    for(j=0;j<n;j++)
			    {
    			    if(i!=j&&(a[i][j]==1||a[i][j]==3))
    			    continue outer;
			    }
			    ans++;
			    ar.add(i+1);

			}
		   System.out.println(ans);
		   for(int z:ar)
		   System.out.print(z+" ");
		}
	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


import java.util.Scanner;

public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        String r = "";
        for(int i = 0; i < n; i++) {
            boolean v = true;
            for(int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if(s == 1 || s == 3){
                    v = false;
                    m--;
                }
            }
            if(v){
                r += i+1 + " ";
            }
        }
        System.out.println(m);
        System.out.println(r);
    }
}


import java.util.Scanner;

public class Sol {
      public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        String r = "";
        for(int i = 0; i < n; i++) {
            boolean v = true;
            for(int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if(s == 1 || s == 3 || s == 2){
                    v = false;
                    m--;
                    break;
                }
            }
            if(v){
                r += i+1 + " ";
            }
        }
          System.out.println(m);
          System.out.println(r);
    }
}


import java.util.Scanner;

public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        String r = "";
        for(int i = 0; i < n; i++) {
            boolean v = true;
            for(int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if(s == 1 || s == 3){
                    v = false;
                    m--;
                    break;
                }
            }
            if(v){
                r += i+1 + " ";
            }
        }
        System.out.println(m);
        System.out.println(r);
    }
}


import java.util.Scanner;

public class Sol {
      public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        String r = "";
        boolean v;
        for(int i = 0; i < n; i++) {
            v = true;
            for(int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if(s == 1 || s == 3){
                    v = false;
                    m--;
                    break;
                }
            }
            if(v){
                r += i+1 + " ";
            }
        }
          System.out.println(m);
          System.out.println(r);
    }
}


import java.util.Scanner;

public class Sol {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = n;
        String r = "";
        for(int i = 0; i < n; i++) {
            boolean v = true;
            for(int j = 0; j < n; j++) {
                int s = sc.nextInt();
                if(s == 1 || s == 3){
                    v = false;
                }
            }
            if(!v){
                m--;
                continue;
            }
            r += i+1 + " ";
        }
        System.out.println(m);
        System.out.println(r);
    }
}