#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 4005;

int n, m, p, ans, s[N], t[N], deg[N], dep[N], par[N], dis[N][N], vis[N][N];
vector <int> adj[N], pth[N];
bool del[N], ers[N], rev[N];
vector <pii> bel[N];

inline void DFS(int x) {
  for (auto y : adj[x]) {
    if (y != par[x]) {
      par[y] = x, dep[y] = dep[x] + 1, DFS(y);
    }
  }
}

inline int Dis(int x, int y) {
  if (x == y) {
    return 0;
  }
  if (dis[x][y]) {
    return dis[x][y];
  }
  if (dep[x] >= dep[y]) {
    return dis[x][y] = Dis(par[x], y) + 1;
  } else {
    return dis[x][y] = Dis(x, par[y]) + 1;
  }
}

inline void Add(int i, int x, int y) {
  if (x == y) {
    return ;
  }
  s[i] = x, t[i] = y;
  vector <int> l, r;
  int u = x, v = y;
  while (u != v) {
    if (dep[u] >= dep[v]) {
      l.pb(u), u = par[u];
    } else {
      r.pb(v), v = par[v];
    }
  }
  reverse(r.begin(), r.end());
  for (auto p : l) {
    pth[i].pb(p);
  }
  pth[i].pb(u);
  for (auto p : r) {
    pth[i].pb(p);
  }
  for (int j = 0; j < pth[i].size(); ++j) {
    bel[pth[i][j]].pb(mp(i, j));
    if (j < pth[i].size() - 1) {
      u = pth[i][j], v = pth[i][j + 1];
      if (u > v) {
        swap(u, v);
      }
      if (vis[u][v] < 2) {
        ++vis[u][v], ++ans;
      }
    }
  }
}

inline bool Go(int i, int j, int x) {
  return (j < pth[i].size() - 1 && pth[i][j + 1] == x) || (j && pth[i][j - 1] == x);
}

inline int Get(int i, int j, int x) {
  return j < pth[i].size() - 1 && pth[i][j + 1] == x ? pth[i].back() : pth[i][0];
}

inline void Make(int i, int x, int y) {
  if (rev[i]) {
    swap(x, y);
  }
  if (Dis(s[i], x) + Dis(y, t[i]) + 1 != Dis(s[i], t[i])) {
    rev[i] = !rev[i];
  }
}

inline void Solve() {
  int x = 0;
  for (int i = 1; i <= n; ++i) {
    if (!ers[i] && deg[i] == 1) {
      x = i;
    }
  }
  if (!x) {
    return ;
  }
  int y = 0;
  for (auto p : adj[x]) {
    if (!ers[p]) {
      y = p;
    }
  }
  ers[x] = true, --deg[y];
  pii a = mp(0, 0), b = mp(0, 0);
  for (auto p : bel[x]) {
    if (!del[p.X] && Go(p.X, p.Y, y)) {
      if (a.X) {
        b = p;
      } else {
        a = p;
      }
    }
  }
  if (!b.X) {
    Solve();
  } else {
    Make(a.X, y, x), Make(b.X, x, y);
    Add(++p, Get(a.X, a.Y, y), Get(b.X, b.Y, y));
    del[a.X] = del[b.X] = true;
    int q = p;
    Solve();
    rev[a.X] ^= rev[q], rev[b.X] ^= rev[q];
  }
}

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n), Read(m);
  for (int i = 1, x, y; i < n; ++i) {
    Read(x), Read(y);
    adj[x].pb(y), adj[y].pb(x);
    ++deg[x], ++deg[y];
  }
  DFS(1);
  for (int i = 1, x, y; i <= m; ++i) {
    Read(x), Read(y);
    Add(++p, x, y);
  }
  printf("%d\n", ans);
  Solve();
  for (int i = 1; i <= m; ++i) {
    if (rev[i]) {
      printf("%d %d\n", t[i], s[i]);
    } else {
      printf("%d %d\n", s[i], t[i]);
    }
  }
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}


Measured memory_bytes: 93952