#include <bits/stdc++.h>
using namespace std;
const int N = 900005;
vector<int> e[N];
int nd, n, X[N], Y[N];
int fa[N], ch[N][2];
int v[N], mxl[N], mxr[N];
bool rev[N];
bool lson(int x) { return x == ch[fa[x]][1]; }
bool isroot(int x) { return x != ch[fa[x]][0] && x != ch[fa[x]][1]; }
void rever(int x) {
  if (!x) return;
  rev[x] ^= 1;
  swap(ch[x][0], ch[x][1]);
  swap(mxl[x], mxr[x]);
}
void pushdown(int x) {
  if (!rev[x]) return;
  rever(ch[x][0]);
  rever(ch[x][1]);
  rev[x] ^= 1;
}
void pushup(int x) {
  int l = mxr[ch[x][0]];
  int r = mxr[ch[x][1]];
  if (v[x] >= v[l])
    mxr[x] = (v[x] > v[r] ? x : r);
  else
    mxr[x] = (v[l] > v[r] ? l : r);
  l = mxl[ch[x][0]];
  r = mxl[ch[x][1]];
  if (v[x] >= v[r])
    mxl[x] = (v[x] > v[l] ? x : l);
  else
    mxl[x] = (v[r] > v[l] ? r : l);
}
void rotate(int x) {
  int y = fa[x], z = fa[y], l = lson(x), r = l ^ 1;
  if (!isroot(y)) ch[z][lson(y)] = x;
  fa[x] = z;
  fa[y] = x;
  fa[ch[x][r]] = y;
  ch[y][l] = ch[x][r];
  ch[x][r] = y;
  pushup(y);
  pushup(x);
}
void Down(int x) {
  if (!isroot(x)) Down(fa[x]);
  pushdown(x);
}
void splay(int x) {
  Down(x);
  for (; !isroot(x); rotate(x))
    if (!isroot(fa[x])) rotate(lson(x) ^ lson(fa[x]) ? x : fa[x]);
}
void access(int x) {
  for (int y = 0; x; y = x, x = fa[x]) splay(x), ch[x][1] = y, pushup(x);
}
void makeroot(int x) {
  access(x);
  splay(x);
  rever(x);
}
void link(int x, int y) {
  makeroot(x);
  access(y);
  fa[x] = y;
}
void cut(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
  fa[x] = ch[y][0] = 0;
  pushup(x);
}
int find(int x, int y) {
  makeroot(x);
  access(y);
  splay(y);
  assert(fa[x]);
  return mxr[y];
}
void dfs(int x, int fa) {
  for (int i = (int)(0); i <= (int)(e[x].size() - 1); i++) {
    int y = e[x][i];
    if (y == fa) continue;
    dfs(y, x);
    int id = find(x, y);
    cut(id, X[id]);
    cut(id, Y[id]);
    printf("%d %d %d %d\n", x, y, X[id], Y[id]);
    X[++nd] = x;
    Y[nd] = y;
    v[nd] = 1;
    link(X[nd], nd);
    link(Y[nd], nd);
  }
}
int main() {
  scanf("%d", &n);
  nd = n;
  for (int i = (int)(1); i <= (int)(n); i++) mxl[i] = mxr[i] = i;
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    e[x].push_back(y);
    e[y].push_back(x);
  }
  for (int i = (int)(1); i <= (int)(n - 1); i++) {
    v[++nd] = 2;
    scanf("%d%d", &X[nd], &Y[nd]);
    link(X[nd], nd);
    link(Y[nd], nd);
  }
  printf("%d\n", n - 1);
  dfs(1, 0);
}
