#include <bits/stdc++.h>
using namespace std;
int read();
int n, m;
int deg[2003], hd[2003], nx[4003], to[4003], cnt;
void add(int u, int v) {
    nx[++cnt] = hd[u], hd[u] = cnt, to[cnt] = v, ++deg[u];
    nx[++cnt] = hd[v], hd[v] = cnt, to[cnt] = u, ++deg[v];
}

set<int> s[2003];
struct E {
    int iu, iv, nu, nv, fa, res;
    void init(int id) {
        iu = nu = read(), iv = nv = read(), s[nu].insert(id), s[nv].insert(id);
    }
    void trans(int u, int v) { (nu == u ? nu : nv) = v; }
} e[2003];

queue<int> q;

int tag[2003];
int Tag(int u, int fa, int t1, int t2) {
    if (u == t1) return 1;
    if (u == t2) return 2;
    int rt = 0;
    for (int i = hd[u], v, t; i; i = nx[i])
        if ((v = to[i]) != fa) {
            if ((t = Tag(v, u, t1, t2)) == 3) return tag[i >> 1] = 1, 3;
            rt |= t;
        }
    return rt;
}
void work() {
    for (int u = 1; u <= n; ++u)
        if (deg[u] == 1) q.push(u);
    for (int u, v, a, b; !q.empty();) {
        u = q.front(), v = a = 0, q.pop();
        for (int i = hd[u]; i; i = nx[i])
            if (deg[v = to[i]] > 1) {
                a = i >> 1;
                break;
            }
        if (!v) continue;
        if ((--deg[v]) == 1) q.push(v);
        if (!s[u].size()) continue;
        // cerr << "############################################ " << u << ' '
        //  << s[1].size() << endl;

        if (tag[a] || s[u].size() == 1) {
            for (; s[u].size(); s[u].erase(a)) {
                a = *s[u].begin(), e[a].trans(u, v);
                e[a].nu != e[a].nv ? (s[v].insert(a), void())
                                   : (s[e[a].nu].erase(a), void());
            }
        } else {
            a = *s[u].begin(), s[u].erase(s[u].begin());
            b = *s[u].begin(), s[u].erase(s[u].begin());
            e[a].nv == u ? (e[a].res ^= 1, swap(e[a].nu, e[a].nv)) : void();
            e[b].nv == u ? (e[b].res ^= 1, swap(e[b].nu, e[b].nv)) : void();
            s[e[a].nv].erase(a), s[e[b].nv].erase(b), e[a].nu = e[b].nv;
            // cerr << "#" << u << '|' << "[" << a << ' ' << e[a].nu << ' '
            //  << e[a].nv << "][" << b << ' ' << e[b].nu << ' ' << e[b].nv
            //  << "]\n";
            // cerr << s[1].size() << ' ' << e[a].nu << ' ' << e[a].nv << endl;
            if (e[a].nu != e[a].nv) s[e[a].nu].insert(a), s[e[a].nv].insert(a);
            e[b].fa = a, e[b].res ^= 1 ^ e[a].res;
            // cerr << e[a].nu << ' ' << e[a].nv << ' ' << "(" << e[a].res << '
            // '
            //  << e[b].res << ")" << endl;
            // cerr << s[1].size() << endl;

            Tag(u, 0, e[a].nu, e[a].nv);
            for (; s[u].size(); s[u].erase(a)) {
                a = *s[u].begin(), e[a].trans(u, v);
                e[a].nu != e[a].nv ? (s[v].insert(a), void())
                                   : (s[e[a].nu].erase(a), void());
            }
        }
    }
}

int vis[2003];
int get(int i) {
    if (!i) return 0;
    if (vis[i]) return e[i].res;
    vis[i] = 1;
    return e[i].res ^= get(e[i].fa);
}

int res;
int sum[2003];
bool ins(int u, int fa, int t) {
    if (u == t) return 1;
    for (int i = hd[u], v; i; i = nx[i])
        if ((v = to[i]) != fa)
            if (ins(v, u, t)) return ++sum[i >> 1], 1;
    return 0;
}
void solve() {
    for (int i = 1; i <= m; ++i) ins(e[i].iu, 0, e[i].iv);
    for (int i = 1; i < n; ++i) res += (sum[i] > 0) + (sum[i] > 1);
}

bool ins2(int u, int fa, int t) {
    if (u == t) return 1;
    for (int i = hd[u], v; i; i = nx[i])
        if ((v = to[i]) != fa)
            if (ins2(v, u, t)) return sum[i >> 1] |= 1 << (i & 1), 1;
    return 0;
}
void solve2() {
    res = 0;
    for (int i = 1; i < n; ++i) sum[i] = 0;
    for (int i = 1; i <= m; ++i) ins2(e[i].iu, 0, e[i].iv);
    for (int i = 1; i < n; ++i) res += (sum[i] >> 1) + (sum[i] & 1);
    cout << res << endl;
}

int main() {
    n = read(), m = read(), cnt = 1;
    for (int i = 1; i < n; ++i) add(read(), read());
    for (int i = 1; i <= m; ++i) e[i].init(i);
    work(), solve(), printf("%d\n", res);
    for (int i = 1; i <= m; ++i) {
        get(i) ? swap(e[i].iu, e[i].iv) : void();
        // cerr << "FF" << i << ' ' << e[i].fa << ' ' << get(i) << endl;
        printf("%d %d\n", e[i].iu, e[i].iv);
    }
    // solve2();
    return 0;
}
int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (!isdigit(c)) f = (c == '-') ? -1 : f, c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 768