#include <bits/stdc++.h>
using namespace std;
int N, p[500001];
pair<int, int> tree1[500001], tree2[500001];
vector<pair<int, int> > g1[500001];
list<int> g2[500001];
list<int>::iterator edges[500001][2];
int parent(int x) { return (p[x] == x) ? x : (p[x] = parent(p[x])); }
void merge(int x, int y) { p[parent(x)] = parent(y); }
void dfs(int x, int p = 0) {
  for (auto e : g1[x]) {
    int y = e.first, e1 = e.second;
    if (y != p) {
      dfs(y, x);
      int yy = parent(y);
      int e2 = *g2[yy].begin();
      printf("%d %d %d %d\n", tree1[e1].first, tree1[e1].second,
             tree2[e2].first, tree2[e2].second);
      int a = parent(tree2[e2].first), b = parent(tree2[e2].second);
      g2[a].erase(edges[e2][0]);
      g2[b].erase(edges[e2][1]);
      g2[a].splice(g2[a].begin(), g2[b]);
      merge(b, a);
    }
  }
}
int main() {
  scanf("%d", &N);
  iota(p + 1, p + N + 1, 1);
  for (int i = 0; i < (N - 1); ++i) {
    scanf("%d%d", &tree1[i].first, &tree1[i].second);
    if (tree1[i].first > tree1[i].second) swap(tree1[i].first, tree1[i].second);
  }
  for (int i = 0; i < (N - 1); ++i) {
    scanf("%d%d", &tree2[i].first, &tree2[i].second);
    if (tree2[i].first > tree2[i].second) swap(tree2[i].first, tree2[i].second);
  }
  sort(tree1, tree1 + N - 1);
  sort(tree2, tree2 + N - 1);
  int i1 = 0, i2 = 0, N1 = 0, N2 = 0;
  while (i1 < N - 1 || i2 < N - 1) {
    if (i1 < N - 1 && i2 < N - 1 && tree1[i1] == tree2[i2]) {
      merge(tree1[i1].first, tree1[i1].second);
      ++i1;
      ++i2;
    } else if (i2 == N - 1 ||
               (i1 < N - 1 && i2 < N - 1 && tree1[i1] < tree2[i2])) {
      if (N1 != i1) tree1[N1] = tree1[i1];
      ++N1;
      ++i1;
    } else {
      if (N2 != i2) tree2[N2] = tree2[i2];
      ++N2;
      ++i2;
    }
  }
  for (int i = 0; i < (N1); ++i) {
    int a = parent(tree1[i].first), b = parent(tree1[i].second);
    g1[a].emplace_back(b, i);
    g1[b].emplace_back(a, i);
  }
  for (int i = 0; i < (N2); ++i) {
    int a = parent(tree2[i].first), b = parent(tree2[i].second);
    g2[a].push_front(i);
    edges[i][0] = g2[a].begin();
    g2[b].push_front(i);
    edges[i][1] = g2[b].begin();
  }
  printf("%d\n", N1);
  dfs(parent(1));
  return 0;
}
