#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
vector<int> e[2][N];
int n, fa[2][N], f[N];
int top, ans[N][4];
int get(int x) { return x == f[x] ? x : f[x] = get(f[x]); }
void dfs(int T, int x) {
  for (auto i : e[T][x])
    if (i != fa[T][x]) {
      fa[T][i] = x;
      dfs(T, i);
    }
}
void solve(int x) {
  for (auto i : e[0][x])
    if (i != fa[0][x]) {
      solve(i);
      if (i != fa[1][x] && x != fa[1][i]) {
        ++top;
        ans[top][0] = x;
        ans[top][1] = i;
        ans[top][2] = get(i);
        ans[top][3] = fa[1][get(i)];
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int T = (int)(0); T <= (int)(1); T++) {
    for (int i = (int)(1); i <= (int)(n - 1); i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      e[T][x].push_back(y);
      e[T][y].push_back(x);
    }
    dfs(T, 1);
  }
  f[1] = 1;
  for (int i = (int)(2); i <= (int)(n); i++) {
    int v = fa[1][i];
    if (fa[0][i] == v || fa[0][v] == i)
      f[i] = v;
    else
      f[i] = i;
  }
  solve(1);
  printf("%d\n", top);
  for (int i = (int)(1); i <= (int)(top); i++)
    for (int j = (int)(0); j <= (int)(3); j++)
      printf("%d%c", ans[i][j], j == 3 ? '\n' : ' ');
}
