#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
inline int read() {
  static char ch;
  bool sgn = false;
  while (ch = getchar(), ch < '0' || ch > '9')
    if (ch == '-') sgn = true;
  int res = ch - 48;
  while (ch = getchar(), ch >= '0' && ch <= '9') res = res * 10 + ch - 48;
  return sgn ? -res : res;
}
const int N = 5e5 + 5;
vector<int> E[2][N];
int ans[N][4], fa[2][N], f[N];
void dfs(int id, int x, int f) {
  fa[id][x] = f;
  for (int i = 0; i < E[id][x].size(); i++) {
    int u = E[id][x][i];
    if (u == f) continue;
    dfs(id, u, x);
  }
}
int find(int x) {
  if (f[x] == x) return x;
  return find(f[x]);
}
void solve(int x, int f) {
  for (int i = 0; i < E[0][x].size(); i++) {
    int u = E[0][x][i];
    if (u == f) continue;
    solve(u, x);
  }
  if (fa[1][x] == f || fa[1][f] == x || f == 0) return;
  int t = ++ans[0][0];
  int p = find(x);
  ans[t][0] = x;
  ans[t][1] = f;
  ans[t][2] = p;
  ans[t][3] = fa[1][p];
}
int main() {
  int n = read();
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    E[0][x].push_back(y);
    E[0][y].push_back(x);
  }
  for (int i = 1; i < n; i++) {
    int x = read(), y = read();
    E[1][x].push_back(y);
    E[1][y].push_back(x);
  }
  dfs(0, 1, 0);
  dfs(1, 1, 0);
  for (int i = 1; i <= n; i++) {
    if (fa[0][i] == fa[1][i] || fa[0][fa[1][i]] == i)
      f[i] = fa[1][i];
    else
      f[i] = i;
  }
  solve(1, 0);
  cout << ans[0][0] << endl;
  for (int i = 1; i <= ans[0][0]; i++, puts(""))
    for (int j = 0; j < 4; j++) printf("%d ", ans[i][j]);
}
