#include <bits/stdc++.h>
int n;
struct mjj {
  int x, y;
} a[500001], b[500001];
int fa[500001];
int head[500001], end[1000001], len[1000001], next[1000001], tp;
int head2[500001], end2[1000001], len2[1000001], next2[1000001], tp2;
int dad[500001], db[500001], dad2[500001], db2[500001], wz[500001], gs;
int ans;
int cmp(mjj x, mjj y) { return x.x < y.x || x.x == y.x && x.y < y.y; }
int find(int p) { return p == fa[p] ? p : fa[p] = find(fa[p]); }
void dfs(int p) {
  int i, j, k;
  wz[++gs] = p;
  for (i = head[p]; i; i = next[i])
    if (end[i] != dad[p]) {
      dad[end[i]] = p;
      db[end[i]] = len[i];
      dfs(end[i]);
    }
}
void dfs2(int p) {
  int i, j, k;
  for (i = head2[p]; i; i = next2[i])
    if (end2[i] != dad2[p]) {
      dad2[end2[i]] = p;
      db2[end2[i]] = len2[i];
      dfs2(end2[i]);
    }
}
int main() {
  int i, j, k;
  scanf("%d", &n);
  for (i = 1; i < n; i++) {
    scanf("%d%d", &a[i].x, &a[i].y);
    if (a[i].x > a[i].y) {
      int t = a[i].x;
      a[i].x = a[i].y;
      a[i].y = t;
    }
  }
  for (i = 1; i < n; i++) {
    scanf("%d%d", &b[i].x, &b[i].y);
    if (b[i].x > b[i].y) {
      int t = b[i].x;
      b[i].x = b[i].y;
      b[i].y = t;
    }
  }
  std::sort(a + 1, a + n, cmp);
  std::sort(b + 1, b + n, cmp);
  for (i = 1; i <= n; i++) fa[i] = i;
  ans = n - 1;
  for (i = 1, j = 1; i < n && j < n;) {
    if (cmp(a[i], b[j]))
      i++;
    else if (cmp(b[j], a[i]))
      j++;
    else {
      if (find(a[i].x) != find(a[i].y)) {
        fa[fa[a[i].x]] = fa[a[i].y];
        ans--;
      }
      i++;
      j++;
    }
  }
  for (i = 1; i <= n; i++) find(i);
  for (i = 1; i < n; i++)
    if (fa[a[i].x] != fa[a[i].y]) {
      int x = fa[a[i].x], y = fa[a[i].y];
      next[++tp] = head[x];
      head[x] = tp;
      end[tp] = y;
      len[tp] = i;
      next[++tp] = head[y];
      head[y] = tp;
      end[tp] = x;
      len[tp] = i;
    }
  for (i = 1; i < n; i++)
    if (fa[b[i].x] != fa[b[i].y]) {
      int x = fa[b[i].x], y = fa[b[i].y];
      next2[++tp2] = head2[x];
      head2[x] = tp2;
      end2[tp2] = y;
      len2[tp2] = i;
      next2[++tp2] = head2[y];
      head2[y] = tp2;
      end2[tp2] = x;
      len2[tp2] = i;
    }
  dfs(fa[1]);
  dfs2(fa[1]);
  printf("%d\n", ans);
  for (i = gs; i > 1; i--)
    printf("%d %d %d %d\n", a[db[wz[i]]].x, a[db[wz[i]]].y, b[db2[wz[i]]].x,
           b[db2[wz[i]]].y);
  return 0;
}
