#ifndef LOCAL
#pragma GCC optimize ("O3")
#endif

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (c it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(x...) " [" #x ": " << (x) << "] "

using ld = long double;
using ll = long long;

constexpr int mod = 1000 * 1000 * 1000 + 7;
constexpr int odw2 = (mod + 1) / 2;

void OdejmijOd(int& a, int b) { a -= b; if (a < 0) a += mod; }
int Odejmij(int a, int b) { OdejmijOd(a, b); return a; }
void DodajDo(int& a, int b) { a += b; if (a >= mod) a -= mod; }
int Dodaj(int a, int b) { DodajDo(a, b); return a; }
int Mnoz(int a, int b) { return (ll) a * b % mod; }
void MnozDo(int& a, int b) { a = Mnoz(a, b); }
int Pot(int a, int b) { int res = 1; while (b) { if (b % 2 == 1) MnozDo(res, a); a = Mnoz(a, a); b /= 2; } return res; }
int Odw(int a) { return Pot(a, mod - 2); }
void PodzielDo(int& a, int b) { MnozDo(a, Odw(b)); }
int Podziel(int a, int b) { return Mnoz(a, Odw(b)); }
int Moduluj(ll x) { x %= mod; if (x < 0) x += mod; return x; }

template <typename T> T Maxi(T& a, T b) { return a = max(a, b); }
template <typename T> T Mini(T& a, T b) { return a = min(a, b); }

constexpr int nax = 4005;

bool odw[nax];
vector<pair<int, int>> syf[nax];

vector<pair<int, int>> cyk;

void Dawaj(int w) {
  for (auto& it : syf[w]) {
    if (odw[it.second]) continue;
    odw[it.second] = true;
    Dawaj(it.first);
    cyk.emplace_back(it);
  }
}

vector<pair<int, int>> Znajdz(int w) {
  cyk.clear();
  Dawaj(w);
  return cyk;
}

int n, m;
int prel;
int pre[nax], pos[nax];
vector<int> graf[nax];
int ojc[nax];
int cnt[nax];

void Dfs(int w, int o) {
  ojc[w] = o;
  pre[w] = ++prel;
  for (int x : graf[w]) {
    if (x == o) continue;
    Dfs(x, w);
  }
  pos[w] = prel;
}

bool Przodek(int a, int b) {
  return pre[a] <= pre[b] and pos[b] <= pos[a];
}

void Policz(int a, int b) {
  while (!Przodek(a, b)) {
    cnt[a]++;
    a = ojc[a];
  }
  while (!Przodek(b, a)) {
    cnt[b]++;
    b = ojc[b];
  }
}

bool juz[nax][2];

void Zalicz(int a, int b) {
  while (!Przodek(a, b)) {
    juz[a][0] = true;
    a = ojc[a];
  }
  while (!Przodek(b, a)) {
    juz[b][1] = true;
    b = ojc[b];
  }
}

int nast;
int Niep(int w, int o) {
  int ost = -1;
  if ((int) syf[w].size() % 2 == 1) ost = w;
  for (int x : graf[w]) {
    if (x == o) continue;
    const int tu = Niep(x, w);
    if (tu != -1) {
      if (ost == -1) {
        ost = tu;
      } else {
        syf[ost].emplace_back(tu, nast);
        syf[tu].emplace_back(ost, nast);
        nast++;
        ost = -1;
      }
    }
  }
  return ost;
}

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    graf[a].push_back(b);
    graf[b].push_back(a);
  }
  Dfs(1, -1);
  vector<int> zost;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    zost.push_back(i);
    Policz(a, b);

    syf[a].emplace_back(b, i);
    syf[b].emplace_back(a, i);
  }
  int policz = 0;
  for (int i = 1; i <= n; i++) policz += min(2, cnt[i]);
  cout << policz << endl;

  nast = m;
  const int costam = Niep(1, -1);
  assert(costam == -1);

  #ifdef LOCAL
  for (int i = 1; i <= n; i++) {
    debug() << "syf[" << i << "] = " << syf[i];
  }
  #endif
  vector<pair<int, int>> res(nast);
  for (int i = 1; i <= n; i++) {
    vector<pair<int, int>> cykl = Znajdz(i);
    debug() << imie(cykl);
    const int s = (int) cykl.size();
    for (int j = 0; j < s; j++) {
      const int k = (j + 1) % s;
      res[cykl[j].second] = {cykl[j].first, cykl[k].first};
    }
  }
  for (int i = 0; i < m; i++) {
    cout << res[i].first << " " << res[i].second << "\n";
  }
  #ifdef LOCAL
  for (int i = 0; i < m; i++) {
    Zalicz(res[i].first, res[i].second);
  }
  int wyniczek = 0;
  for (int i = 1; i <= n; i++) wyniczek += juz[i][0] + juz[i][1];
  debug() << imie(policz) imie(wyniczek);
  assert(policz == wyniczek);
  #endif
  return 0;
}


Measured memory_bytes: 896