#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 50;
int n, cnt, f[N][18], d[N], fa[N], id[N], s[N];
vector<int> v1[N], v2[N];
void dfs1(int x, int ff) {
  for (int i = 0; i < 17; i++) f[x][i + 1] = f[f[x][i]][i];
  for (int i = 0, y; i < v1[x].size(); i++)
    if ((y = v1[x][i]) != ff)
      f[y = v1[x][i]][0] = x, d[y] = d[x] + 1, dfs1(y, x);
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
void merge(int x, int y) {
  x = find(x);
  y = find(y);
  if (s[x] > s[y]) swap(x, y);
  fa[x] = y;
  s[y] += s[x];
  id[y] = d[id[y]] < d[id[x]] ? id[y] : id[x];
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = 17; ~i; i--)
    if (d[f[x][i]] >= d[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 17; ~i; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
void dfs2(int x, int ff) {
  for (int i = 0, y; i < v2[x].size(); i++)
    if ((y = v2[x][i]) != ff) dfs2(y, x);
  if (!ff) return;
  int l = lca(x, ff);
  int fx = find(x), fl = find(l), p = ff;
  if (fx != fl)
    p = id[fx];
  else
    for (int i = 17; ~i; i--)
      if (d[f[p][i]] > d[l] && find(f[p][i]) != fl) p = f[p][i];
  merge(p, f[p][0]);
  printf("%d %d %d %d\n", p, f[p][0], x, ff);
}
int main() {
  scanf("%d", &n);
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), v1[x].push_back(y), v1[y].push_back(x);
  for (int i = 1, x, y; i < n; i++)
    scanf("%d%d", &x, &y), v2[x].push_back(y), v2[y].push_back(x);
  printf("%d\n", n - 1);
  for (int i = 1; i <= n; i++) id[i] = fa[i] = i, s[i] = 1;
  dfs1(d[1] = 1, 0);
  dfs2(1, 0);
  return 0;
}
