#include <bits/stdc++.h>
using namespace std;
inline int IN() {
  char c;
  register int first = 0;
  for (; (c = getchar()) < 48 && c ^ '-' || c > 57;)
    ;
  bool f = c == '-';
  if (f) (c = getchar());
  for (; c > 47 && c < 58; (c = getchar()))
    first = (first << 3) + (first << 1) + c - 48;
  if (f) first = -first;
  return first;
}
inline void glance() { freopen("ha.in", "r", stdin); }
int n, m, F[500005];
struct Info {
  int a, b, c, d;
} g[500005];
struct Tree {
  int fa[500005];
  vector<int> Ed[500005];
  void Link(int u, int v) {
    Ed[u].push_back(v);
    Ed[v].push_back(u);
  }
  void dfs(int u) {
    for (int v : Ed[u]) {
      if (v ^ fa[u]) {
        fa[v] = u;
        dfs(v);
      }
    }
  }
} T1, T2;
int get(int first) {
  return first ^ F[first] ? F[first] = get(F[first]) : first;
}
void DFS(int u) {
  for (int v : T1.Ed[u]) {
    if (v ^ T1.fa[u]) {
      DFS(v);
    }
  }
  int w = T1.fa[u], v = T2.fa[get(u)];
  if (T2.fa[w] == u)
    F[F[w]] = F[u];
  else if (T2.fa[u] == w)
    F[F[u]] = F[w];
  else {
    g[++m] = {u, w, get(u), T2.fa[get(u)]};
    F[get(u)] = get(v);
  }
}
int main() {
  n = IN();
  for (int _r = n, i = 1; i < _r; ++i) T1.Link(IN(), IN());
  for (int _r = n, i = 1; i < _r; ++i) T2.Link(IN(), IN());
  T1.dfs(1);
  T2.dfs(1);
  for (int _r = n, i = 1; i <= _r; ++i) F[i] = i;
  DFS(1);
  printf("%d\n", m);
  for (int _r = m, i = 1; i <= _r; ++i)
    printf("%d %d %d %d\n", g[i].a, g[i].b, g[i].c, g[i].d);
}
