#include <bits/stdc++.h>
using namespace std;
const int NMAX = 555555;
vector<int> g1[NMAX], g2[NMAX];
int p1[NMAX], p2[NMAX];
int target[NMAX];
vector<tuple<int, int, int, int> > ans;
void dfs1_1(int r, int p) {
  if (p1[r]) return;
  p1[r] = p;
  for (int c : g1[r]) dfs1_1(c, r);
}
void dfs1_2(int r, int p) {
  if (p2[r]) return;
  p2[r] = p;
  for (int c : g2[r]) dfs1_2(c, r);
}
void ready(int r) {
  if (p1[r] != p2[r] && p1[p2[r]] != r)
    target[r] = r;
  else
    target[r] = target[p2[r]];
  for (int c : g2[r])
    if (p2[r] != c) ready(c);
}
void go(int r) {
  for (int c : g1[r])
    if (p1[r] != c) go(c);
  if (p1[r] != p2[r] && p2[p1[r]] != r) {
    ans.push_back(
        tuple<int, int, int, int>(r, p1[r], target[r], p2[target[r]]));
  }
}
int main() {
  cin.sync_with_stdio(0), cout.sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g1[a].push_back(b), g1[b].push_back(a);
  }
  dfs1_1(1, -1);
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g2[a].push_back(b), g2[b].push_back(a);
  }
  dfs1_2(1, -1);
  ready(1);
  go(1);
  cout << ans.size() << endl;
  for (auto& t : ans) {
    cout << get<0>(t) << ' ' << get<1>(t) << ' ' << get<2>(t) << ' '
         << get<3>(t) << endl;
  }
}
