#include<bits/stdc++.h>

using namespace std;

int N, M, side[2018], mars[2019], lca[2009][2009], sol[200009], leftEnd[2009], rightEnd[2009], lft[2009], rgt[2009], lev[2009], t[2009];
set < int > v[2009];

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

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;
}

void delEdge (int x, int y)
{
    v[x].erase (y);
    v[y].erase (x);
}

bool isXinSubtreeOfY (int x, int y)
{
    return (lft[y] <= lft[x] && rgt[x] <= rgt[y]);
}

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

int cntQ, cc[2018], bigAns, 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 < int > &currNodes, vector < pair < int, pair < int, int > > > &paths)
{
    if (currNodes.size () <= 1) return ;
/*    printf ("[");
    for (auto it : currNodes)
        printf ("%d ", it);
    printf ("], [\n");
    for (auto it : paths)
        printf ("[[%d, %d] %d]\n", it.second.first, it.second.second, it.first);
    printf ("]\n");*/
    int root = currNodes[0];
    for (auto it : currNodes)
        if (lev[it] < lev[root])
            root = it;
    int nr = 1;
    cc[1] = root, ap[root] = 1;
    for (int i=1; i<=nr; i++)
    {
        int nod = cc[i];
        for (auto it : v[nod])
            if (ap[it] == 0)
                ap[it] = 1, cc[++nr] = it;
    }
    for (int i=1; i<=nr; i++)
        ap[cc[i]] = 0;
    for (auto it : currNodes)
        if (it != root)
            mars[it] = 0;
    for (auto qq : paths)
    {
        int x = qq.second.first, y = qq.second.second;
        mars[x] ++, mars[y] ++, mars[lca[x][y]] -= 2;
    }
    for (int i=nr; i>1; i--)
        mars[t[cc[i]]] += mars[cc[i]];
    if (nr == N)
    {
        bigAns = 0;
        for (int i=2; i<=N; i++)
            bigAns += min (mars[i], 2);
    }
    int edge = -1;
    for (auto it : currNodes)
        if (v[it].size () == 1)
            edge = it;
    delEdge (edge, t[edge]);
    vector < int > curr;
    for (auto it : currNodes)
        if (it != edge)
            curr.push_back (it);
    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 (curr, 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 (curr, 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].insert (y);
    v[y].insert (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]}});
}
vector < int > currNodes;
for (int i=1; i<=N; i++)
    currNodes.push_back (i);
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];
solve (currNodes, curr);
printf ("%d\n", bigAns);
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: 75776