#include <bits/stdc++.h>
using namespace std;
vector<int> v[300010], g[300010];
int f[20][300010], p[300010], d[300010], n;
int fd(int x) { return !p[x] ? x : p[x] = fd(p[x]); }
void d1(int x, int fa) {
  for (int i = 1; i < 20; i++) f[i][x] = f[i - 1][f[i - 1][x]];
  for (auto i : v[x])
    if (i != fa) {
      d[i] = d[x] + 1;
      f[0][i] = x;
      d1(i, x);
    }
}
void lk(int x, int y) {
  x = fd(x);
  y = fd(y);
  for (int i = 19; ~i; i--)
    if (d[fd(f[i][x])] > d[y]) x = fd(f[i][x]);
  if (fd(f[0][x]) == y)
    x = fd(x);
  else
    x = fd(y);
  p[x] = f[0][x];
  cout << x << ' ' << p[x] << ' ';
}
void d2(int x, int fa) {
  for (auto i : g[x])
    if (i != fa) {
      d2(i, x);
      lk(x, i);
      cout << x << ' ' << i << '\n';
    }
}
int main() {
  cin >> n;
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (int i = 1; i < n; i++) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  cout << n - 1 << '\n';
  d1(1, 0);
  d2(1, 0);
}
