#include <bits/stdc++.h>
using namespace std;
int n, d[250005], fa[250005][21], lg[250005], f[250005], dep[250005];
bool vst[250005];
vector<int> e1[250005], e2[250005];
queue<int> q;
inline int read() {
  int f = 1, w = 0;
  char ch = 0;
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    w = (w << 1) + (w << 3) + ch - '0', ch = getchar();
  return f * w;
}
void dfs(int k, int f) {
  dep[k] = dep[f] + 1, fa[k][0] = f;
  for (int i = 0; i < e1[k].size(); i++) {
    int v = e1[k][i];
    if (v != f) dfs(v, k);
  }
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  while (dep[x] > dep[y]) x = fa[x][lg[dep[x] - dep[y]]];
  if (x == y) return x;
  for (int i = lg[dep[x]]; ~i; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }
int main() {
  n = read(), lg[0] = -1;
  for (int i = 1; i <= n; i++) lg[i] = lg[i >> 1] + 1, f[i] = i;
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    e1[x].push_back(y), e1[y].push_back(x);
  }
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    e2[x].push_back(y), e2[y].push_back(x), ++d[x], ++d[y];
  }
  dfs(1, 0), printf("%d\n", n - 1);
  for (int i = 1; i <= 20; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  for (int i = 1; i <= n; i++)
    if (d[i] == 1) q.push(i);
  while (q.size() > 1) {
    int u = q.front(), v;
    q.pop(), vst[u] = true;
    for (int i = 0; i < e2[u].size(); i++)
      if (!vst[e2[u][i]]) {
        --d[e2[u][i]], v = e2[u][i];
        if (d[e2[u][i]] == 1) q.push(e2[u][i]);
        break;
      }
    int lca = LCA(u, v), a = find(u), b;
    if (dep[a] > dep[lca])
      b = fa[a][0], printf("%d %d %d %d\n", a, b, u, v), f[a] = b;
    else {
      b = v;
      for (int i = 20; ~i; i--)
        if (dep[fa[b][i]] > dep[lca] && find(fa[b][i]) != a) b = fa[b][i];
      printf("%d %d %d %d\n", b, fa[b][0], u, v), f[b] = a;
    }
  }
  return 0;
}
