#include <bits/stdc++.h>
using namespace std;
struct node {
  int a, b, c, d;
  node() {}
  node(int A, int B, int C, int D) { a = A, b = B, c = C, d = D; }
} ans[500005];
vector<int> G[2][500005];
int n, cnt;
int f[500005];
int fa[2][500005];
void dfs(int u, int k) {
  for (int i = 0; i < G[k][u].size(); i++) {
    int v = G[k][u][i];
    if (v == fa[k][u])
      continue;
    else
      fa[k][v] = u, dfs(v, k);
  }
}
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void makeSet() {
  for (int i = 1; i <= n; i++) {
    int now = fa[1][i];
    if (now == fa[0][i] || i == fa[0][now])
      f[i] = now;
    else
      f[i] = i;
  }
}
void dfs(int u) {
  for (int i = 0; i < G[0][u].size(); i++) {
    int v = G[0][u][i];
    if (v == fa[0][u]) continue;
    dfs(v);
    if (v != fa[1][u] && u != fa[1][v])
      ans[++cnt] = node(u, v, find(v), fa[1][find(v)]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    G[0][u].push_back(v);
    G[0][v].push_back(u);
  }
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    G[1][u].push_back(v);
    G[1][v].push_back(u);
  }
  dfs(1, 0);
  dfs(1, 1);
  makeSet();
  dfs(1);
  printf("%d\n", cnt);
  for (int i = 1; i <= cnt; i++)
    printf("%d %d %d %d\n", ans[i].a, ans[i].b, ans[i].c, ans[i].d);
  return 0;
}
