#include<bits/stdc++.h>

using namespace std;

int N, M, mars[2019], lca[2009][2009], sol[200009], leftEnd[2009], rightEnd[2009], lev[2009], t[2009];
vector < int > v[2009];

void dfs0 (int nod, int tata)
{
    for (auto it : v[nod])
        if (it != tata)
            lev[it] = lev[nod] + 1, t[it] = nod, dfs0 (it, nod);
}

int getLca (int i, int j)
{
    if (i > j) swap (i, j);
    if (lca[i][j] != 0) return lca[i][j];
    int ans;
    if (lev[i] > lev[j]) ans = getLca (t[i], j);
    else ans = getLca (i, t[j]);
    lca[i][j] = ans;
    return ans;
}

int lower (int x, int y)
{
    if (lev[x] < lev[y]) return y;
    return x;
}

void dfs (int nod)
{
    for (auto it : v[nod])
        if (it != t[nod])
            dfs (it), mars[nod] += mars[it];
}

void init ()
{
    dfs0 (1, -1);
    for (int i=1; i<=N; i++)
        lca[i][i] = i;
    for (int i=1; i<=N; i++)
        for (int j=i + 1; j<=N; j++)
            lca[i][j] = getLca (i, j);
    for (int i=1; i<=N; i++)
        for (int j=1; j<i; j++)
            lca[i][j] = lca[j][i];
    for (int i=1; i<=M; i++)
    {
        int x = leftEnd[i], y = rightEnd[i];
        mars[x] ++, mars[y] ++, mars[lca[x][y]] -= 2;
    }
    dfs (1);
    int ans = 0;
    for (int i=2; i<=N; i++)
        ans += min (mars[i], 2);
    printf ("%d\n", ans);
}

int cntQ, done[2018];
bool ap[2018];

void markSolvedPath (int x, int y)
{
    while (x != y)
    {
        if (lev[x] > lev[y]) done[x] = 1, x = t[x];
        else done[y] = 1, y = t[y];
    }
}

void solve (vector < pair < int, pair < int, int > > > &paths)
{
    int edge = -1;
    for (int i=1; i<=N; i++)
        if (ap[i] == 0)
        {
            int sz = 0;
            for (auto it : v[i])
                sz += (ap[it] == 0);
            if (sz == 1)
                edge = i;
        }
    if (edge == -1) return ;
    ap[edge] = 1;
    if (mars[edge] <= 1 || done[edge])
    {
        vector < pair < int, pair < int, int > > > p;
        for (auto it : paths)
        {
            int pos = it.first, x = it.second.first, y = it.second.second;
            if (x == edge) x = t[edge];
            if (y == edge) y = t[edge];
            if (x != y) p.push_back ({pos, {x, y}});
        }
        solve (p);
        return ;
    }
    vector < pair < int, pair < int, int > > > p;
    int pos = ++cntQ, x = -1, y = -1, px, py;
    for (auto it : paths)
        if (it.second.second != it.second.first)
        {
            if (it.second.first != edge && it.second.second != edge) p.push_back (it);
            else
            {
                int z, pz;
                if (it.second.first == edge) z = it.second.second, pz = it.first;
                else z = it.second.first, pz = -it.first;
                if (x == -1) x = z, px = pz;
                else
                if (y == -1) y = z, py = pz;
                else
                if (pz > 0) p.push_back ({it.first, {t[edge], z}});
                else p.push_back ({it.first, {z, t[edge]}});
            }
        }
    int z = lower (lca[x][y], lower (lca[x][t[edge]], lca[y][t[edge]]));
    if (t[edge] != z)
        markSolvedPath (t[edge], z);
    p.push_back ({pos, {x, y}});
    solve (p);
    if (py > 0) sol[py] = sol[pos];
    else sol[-py] = sol[pos] ^ 1;
    if (px < 0) sol[-px] = sol[pos];
    else sol[px] = sol[pos] ^ 1;
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d", &N, &M), cntQ = M;
for (int i=1; i<N; i++)
{
    int x, y;
    scanf ("%d %d", &x, &y);
    v[x].push_back (y);
    v[y].push_back (x);
}
vector < pair < int, pair < int, int > > > curr;
for (int i=1; i<=M; i++)
{
    scanf ("%d %d", &leftEnd[i], &rightEnd[i]);
    curr.push_back ({i, {leftEnd[i], rightEnd[i]}});
}
init ();
solve (curr);
for (int i=1; i<=M; i++)
    if (sol[i]) printf ("%d %d\n", leftEnd[i], rightEnd[i]);
    else printf ("%d %d\n", rightEnd[i], leftEnd[i]);
return 0;
}


Measured memory_bytes: 60544