#include <bits/stdc++.h>
using namespace std;
const int N = 6e5;
int n;
int vis[N];
vector<int> B1[N];
vector<tuple<int, int, int, int> > res;
set<pair<int, int> > B2[N];
int fa[N];
int get_f(int t) { return fa[t] == t ? t : fa[t] = get_f(fa[t]); }
void merge(int a, int b) {
  a = get_f(a);
  b = get_f(b);
  if (B2[a].size() < B2[b].size()) swap(a, b);
  B2[a].insert(B2[b].begin(), B2[b].end());
  fa[b] = a;
}
void dfs(int t, int f = 0) {
  for (auto p : B1[t])
    if (p != f) {
      dfs(p, t);
      if (!B2[get_f(t)].count(make_pair(t, p))) {
        auto q = *B2[get_f(p)].begin();
        merge(q.first, q.second);
        B2[get_f(q.first)].erase(make_pair(q.first, q.second));
        B2[get_f(q.first)].erase(make_pair(q.second, q.first));
        res.push_back(make_tuple(t, p, q.first, q.second));
      } else {
        auto q = make_pair(t, p);
        merge(q.first, q.second);
        B2[get_f(q.first)].erase(make_pair(q.first, q.second));
        B2[get_f(q.first)].erase(make_pair(q.second, q.first));
      }
    }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    B1[a].push_back(b);
    B1[b].push_back(a);
  }
  for (int i = 1; i < n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    B2[a].insert(make_pair(a, b));
    B2[b].insert(make_pair(b, a));
  }
  dfs(1);
  printf("%d\n", res.size());
  for (auto p : res) {
    int a, b, c, d;
    tie(a, b, c, d) = p;
    printf("%d %d %d %d\n", a, b, c, d);
  }
}
