#include <bits/stdc++.h>
using namespace std;
const int N = 250003;
template <typename T>
void read(T &x) {
  int ch = getchar();
  x = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    ;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
}
int n, cnt, head[N], to[N << 1], nxt[N << 1], f[18][N], dep[N], fa[N], d[N],
    q[N], fr, re;
bool vis[N];
void add(int u, int v) {
  to[++cnt] = v;
  nxt[cnt] = head[u];
  head[u] = cnt;
}
void dfs(int x) {
  for (int i = 0; i < 17; ++i) f[i + 1][x] = f[i][f[i][x]];
  for (int i = head[x]; i; i = nxt[i])
    if (to[i] != f[0][x]) {
      f[0][to[i]] = x;
      dep[to[i]] = dep[x] + 1;
      dfs(to[i]);
    }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int k = dep[u] - dep[v];
  for (int i = 17; ~i; --i)
    if (k >> i & 1) u = f[i][u];
  if (u == v) return u;
  for (int i = 17; ~i; --i)
    if (f[i][u] != f[i][v]) {
      u = f[i][u];
      v = f[i][v];
    }
  return f[0][u];
}
vector<int> E[N];
int getf(int x) { return x == fa[x] ? x : fa[x] = getf(fa[x]); }
int main() {
  read(n);
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    add(u, v);
    add(v, u);
  }
  dfs(1);
  for (int i = 1, u, v; i < n; ++i) {
    read(u);
    read(v);
    E[u].emplace_back(v);
    E[v].emplace_back(u);
    ++d[u];
    ++d[v];
  }
  for (int i = 1; i <= n; ++i) {
    fa[i] = i;
    if (d[i] == 1) q[re++] = i;
  }
  printf("%d\n", n - 1);
  while (fr < re - 1) {
    int u = q[fr++], v = 0;
    vis[u] = true;
    for (int _ : E[u])
      if (!vis[_]) {
        --d[v = _];
        if (d[v] == 1) q[re++] = v;
        break;
      }
    int w = lca(u, v), a = getf(u);
    if (dep[a] > dep[w]) {
      printf("%d %d %d %d\n", a, f[0][a], v, u);
      fa[a] = f[0][a];
    } else {
      int b = v;
      for (int i = 17; ~i; --i)
        if (dep[f[i][b]] > dep[w] && getf(f[i][b]) != a) b = f[i][b];
      printf("%d %d %d %d\n", b, f[0][b], v, u);
      fa[b] = a;
    }
  }
}
