#include <bits/stdc++.h>
using namespace std;
const int Maxn = 500005;
int ans[Maxn][4], tot;
int he[2][Maxn], nxt[Maxn << 2], to[Maxn << 2], cnt, fa[2][Maxn];
void addedge(int u, int v, int *head) {
  nxt[++cnt] = head[u], head[u] = cnt, to[cnt] = v;
}
void dfs(int u, int v, int op) {
  for (int i = he[op][u]; i; i = nxt[i])
    if (to[i] != v) fa[op][to[i]] = u, dfs(to[i], u, op);
}
int anc[Maxn];
int find(int x) { return anc[x] == x ? x : anc[x] = find(anc[x]); }
void solve(int u, int v, int op) {
  for (int i = he[op][u]; i; i = nxt[i])
    if (to[i] != v) {
      int e = to[i];
      solve(e, u, op);
      if (find(e) == find(u)) continue;
      ++tot;
      ans[tot][0] = u, ans[tot][1] = e;
      ans[tot][2] = find(e), ans[tot][3] = fa[1][find(e)];
    }
}
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v, he[0]), addedge(v, u, he[0]);
  }
  for (int i = 1, u, v; i < n; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v, he[1]), addedge(v, u, he[1]);
  }
  dfs(1, 0, 0), dfs(1, 0, 1);
  for (int i = 1; i <= n; ++i) anc[i] = i;
  for (int i = 1; i <= n; ++i) {
    int u = fa[1][i];
    if (u != 0 && (fa[0][i] == u || fa[0][u] == i)) anc[find(i)] = find(u);
  }
  solve(1, 0, 0);
  printf("%d\n", tot);
  for (int i = 1; i <= tot; ++i) {
    for (int j = 0; j < 4; ++j) printf("%d ", ans[i][j]);
    puts("");
  }
  return 0;
}
