#include <bits/stdc++.h>
using namespace std;
const int M = 18;
int n;
vector<int> e[250010];
vector<int> to[250010];
int dep[250010];
int f[250010][M];
struct DSU {
  int fa[250010];
  void init(int n) {
    for (int i = 1; i <= n; i++) fa[i] = i;
    return;
  }
  int find(int u) { return fa[u] == u ? u : fa[u] = find(fa[u]); }
  bool same(int u, int v) { return find(u) == find(v); }
  bool merge(int u, int v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    fa[u] = v;
    return true;
  }
} S;
void dfs(int u, int lst) {
  dep[u] = dep[lst] + 1;
  f[u][0] = lst;
  for (int i = 1; i < M; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = 0; i < e[u].size(); i++) {
    int v = e[u][i];
    if (v == lst) continue;
    dfs(v, u);
  }
  return;
}
int getlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int need = dep[u] - dep[v], now = 0;
  while (need) {
    if (need & 1) u = f[u][now];
    now++;
    need >>= 1;
  }
  if (u == v) return u;
  for (int i = M - 1; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
void work(int u, int v) {
  int lca = getlca(u, v), x = 0;
  if (S.same(u, lca)) {
    x = v;
    for (int i = M - 1; i >= 0; i--)
      if (dep[f[x][i]] >= dep[lca] && !S.same(u, f[x][i])) x = f[x][i];
  } else {
    x = u;
    for (int i = M - 1; i >= 0; i--)
      if (dep[f[x][i]] >= dep[lca] && S.same(u, f[x][i])) x = f[x][i];
  }
  printf("%d %d %d %d\n", x, f[x][0], u, v);
  if (!S.same(u, x))
    S.merge(u, x);
  else
    S.merge(u, f[x][0]);
  return;
}
void solve(int u, int lst) {
  for (int i = 0; i < to[u].size(); i++) {
    int v = to[u][i];
    if (v == lst) continue;
    solve(v, u);
    work(v, u);
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    to[u].push_back(v);
    to[v].push_back(u);
  }
  S.init(n);
  dfs(1, 0);
  printf("%d\n", n - 1);
  solve(1, 0);
  return 0;
}
