#include <bits/stdc++.h>
using namespace std;
void read(int &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') f = -f;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  x *= f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (!x) return;
  print(x / 10), putchar(x % 10 + 48);
}
void write(int x) {
  if (!x)
    putchar('0');
  else
    print(x);
  putchar('\n');
}
const int maxn = 1e6 + 10;
const int inf = 1e9;
const double eps = 1e-8;
const int mod = 1e9 + 7;
int s[maxn][2], fa[maxn], mn[maxn], mnp[maxn], n, cnt, val[maxn], tot,
    sta[maxn], top, rev[maxn];
pair<int, int> a[maxn], b[maxn];
map<pair<int, int>, int> pps;
void update(int x) {
  mnp[x] = x;
  mn[x] = val[x];
  for (int i = 0; i < 2; i++)
    if (s[x][i] && mn[s[x][i]] < mn[x]) mn[x] = 0, mnp[x] = mnp[s[x][i]];
}
int nrt(int x) { return s[fa[x]][0] == x || s[fa[x]][1] == x; }
int which(int x) { return s[fa[x]][1] == x; }
void rotate(int x) {
  int y = fa[x], z = fa[y], w = which(x);
  if (nrt(y)) s[z][which(y)] = x;
  fa[x] = z, fa[y] = x;
  fa[s[x][w ^ 1]] = y, s[y][w] = s[x][w ^ 1], s[x][w ^ 1] = y;
  update(y), update(x);
}
void push(int x) { rev[x] ^= 1, swap(s[x][0], s[x][1]); }
void pushdown(int x) {
  if (rev[x]) push(s[x][0]), push(s[x][1]), rev[x] = 0;
}
void splay(int x) {
  int t = x;
  while (nrt(t)) sta[++top] = t, t = fa[t];
  sta[++top] = t;
  while (top) pushdown(sta[top--]);
  while (nrt(x)) {
    int y = fa[x];
    if (nrt(y)) rotate(which(x) == which(y) ? y : x);
    rotate(x);
  }
}
void access(int x) {
  for (int t = 0; x; t = x, x = fa[x]) splay(x), s[x][1] = t, update(x);
}
void make_root(int x) { access(x), splay(x), push(x); }
void link(int x, int y) { make_root(x), fa[x] = y; }
void cut(int x, int y) {
  make_root(x), access(y), splay(y);
  fa[x] = s[y][0] = 0;
  update(y);
}
void modify(int x) { access(x), splay(x), val[x] = 1, update(x); }
int main() {
  read(n);
  cnt = n;
  for (int i = 1; i <= n; i++) val[i] = mn[i] = 1, mnp[i] = i;
  for (int i = 1, x, y; i < n; i++) {
    read(x), read(y);
    if (x > y) swap(x, y);
    a[++cnt] = make_pair(x, y), pps[make_pair(x, y)] = cnt;
    mnp[cnt] = cnt;
    link(x, cnt), link(cnt, y);
  }
  for (int t, i = 1, x, y; i < n; i++) {
    read(x), read(y);
    if (x > y) swap(x, y);
    t = pps[make_pair(x, y)];
    if (t)
      modify(t);
    else
      b[++tot] = make_pair(x, y);
  }
  write(tot);
  for (int i = 1; i <= tot; i++) {
    int x = b[i].first, y = b[i].second;
    make_root(x), access(y), splay(y);
    int p = mnp[y];
    cut(p, a[p].first), cut(p, a[p].second);
    modify(p);
    printf("%d %d %d %d\n", a[p].first, a[p].second, x, y);
    a[p] = make_pair(x, y);
    link(p, x), link(p, y);
  }
  return 0;
}
