#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char ch = getchar();
  int x = 0, f = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
vector<int> a[2][500005];
struct data {
  int a, b, c, d;
} ans[500005];
int n, cnt, fa[2][500005], f[500005];
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
void dfs(int p, int u, int last) {
  for (int j = 0; j < a[p][u].size(); ++j) {
    int v = a[p][u][j];
    if (v == last) continue;
    fa[p][v] = u;
    dfs(p, v, u);
  }
}
void work(int u, int last) {
  for (int j = 0; j < a[0][u].size(); ++j) {
    int v = a[0][u][j];
    if (v == last) continue;
    work(v, u);
    if (u != fa[1][v] && v != fa[1][u]) {
      ans[++cnt] = (data){u, v, find(v), fa[1][find(v)]};
    }
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; ++i) {
    int u = read(), v = read();
    a[0][u].push_back(v);
    a[0][v].push_back(u);
  }
  for (int i = 2; i <= n; ++i) {
    int u = read(), v = read();
    a[1][u].push_back(v);
    a[1][v].push_back(u);
  }
  dfs(0, 1, 0);
  dfs(1, 1, 0);
  for (int u = 2; u <= n; ++u) {
    int v = fa[1][u];
    if (fa[0][u] == v || fa[0][v] == u)
      f[u] = v;
    else
      f[u] = u;
  }
  work(1, 0);
  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);
}
