#include <bits/stdc++.h>
using namespace std;
int nxt[500005], to[500005], head[500005], fa[500005], f[500005][22],
    dep[500005], ru[500005], tot;
bool vis[500005], used[500005];
queue<int> q;
vector<int> ei[500005];
void add(int u, int v) {
  nxt[++tot] = head[u];
  head[u] = tot;
  to[tot] = v;
  nxt[++tot] = head[v];
  head[v] = tot;
  to[tot] = u;
}
void dfs(int u, int p) {
  dep[u] = dep[p] + 1;
  f[u][0] = p;
  for (int i = 1; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int e = head[u]; e; e = nxt[e]) {
    int v = to[e];
    if (v == p) continue;
    dfs(v, u);
  }
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; i >= 0; i--) {
    if (dep[f[x][i]] >= dep[y]) {
      x = f[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 20; i >= 0; i--) {
    if (f[x][i] != f[y][i]) {
      x = f[x][i];
      y = f[y][i];
    }
  }
  return f[x][0];
}
int find(int x) {
  if (x == fa[x]) return x;
  return fa[x] = find(fa[x]);
}
struct sad {
  int x, y;
} a[500005];
int main() {
  int n, x, y, u, v;
  cin >> n;
  for (int i = 1; i <= n; i++) fa[i] = i;
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    ru[a[i].x]++;
    ru[a[i].y]++;
    ei[a[i].x].push_back(i);
    ei[a[i].y].push_back(i);
  }
  dfs(1, 0);
  for (int i = 1; i <= n - 1; i++) {
    if (ru[a[i].x] == 1 || ru[a[i].y] == 1) {
      used[i] = 1;
      q.push(i);
    }
  }
  int ans = 0;
  cout << n - 1 << endl;
  while (!q.empty()) {
    int eg = q.front();
    q.pop();
    u = a[eg].x;
    v = a[eg].y;
    if (ru[u] != 1) swap(u, v);
    int z = lca(u, v);
    int p = find(u);
    if (dep[p] > dep[z]) {
      ans++;
      fa[p] = find(f[p][0]);
      printf("%d %d %d %d\n", p, f[p][0], a[eg].x, a[eg].y);
    } else {
      int t = v;
      for (int i = 20; i >= 0; i--)
        if (dep[f[t][i]] > dep[z] && find(f[t][i]) != p) t = f[t][i];
      fa[t] = find(f[t][0]);
      printf("%d %d %d %d\n", t, f[t][0], a[eg].x, a[eg].y);
    }
    ru[u]--;
    ru[v]--;
    if (ru[v] == 1) {
      int mm = ei[v].size();
      for (int i = 0; i < mm; i++) {
        int ey = ei[v][i];
        if (used[ey] == 0) q.push(ey), used[ey] = 1;
      }
    }
  }
  return 0;
}
