#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
inline char nc()
{
    return getchar();
    static char buf[100000],*l=buf,*r=buf;
    return l==r&&(r=(l=buf)+fread(buf,1,100000,stdin),l==r)?EOF:*l++;
}
template<class T> void read(T &x)
{
    x=0; int f=1,ch=nc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=nc();}
    while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=nc();}
    x*=f;
}
const int maxn=2000+50;
const int maxm=2000+50;
int n,m;
int A[maxm],B[maxm];
int an;
int a[maxm<<1];
int b[maxm<<1];
int q[maxn];
int anc[maxn];
int deg[maxn];
int dep[maxn];
int dir[maxm<<1];
int head[maxn];
int ch[maxm<<1][2];
bool rev[maxm<<1];
bool vis[maxn];
bool mark[maxm<<1];
bool used[maxn][2];
struct edge
{
    int to,nex;
    edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline void addedge(int u,int v)
{
    G.push_back(edge(v,head[u])),head[u]=G.size()-1;
    G.push_back(edge(u,head[v])),head[v]=G.size()-1;
    ++deg[u],++deg[v];
}
void dfs(int u,int c)
{
    if(u==0) return;
    c^=rev[u];
    dir[u]=c;
    dfs(ch[u][0],c);
    dfs(ch[u][1],c^1);
}
void getdep(int u)
{
    for(int i=head[u];~i;i=G[i].nex)
    {
        int v=G[i].to; if(v==anc[u]) continue;
        dep[v]=dep[u]+1;
        anc[v]=u;
        getdep(v);
    }
}
inline void upd(int x,int c)
{
    if(used[x][c]) return;
    used[x][c]=1,++an;
}
int main()
{
    read(n),read(m);
    memset(head,-1,sizeof(head));
    for(int i=1;i<n;++i)
    {
        int a,b; read(a),read(b);
        addedge(a,b);
    }
    for(int i=1;i<=m;++i)
    {
        read(A[i]),a[i]=A[i];
        read(B[i]),b[i]=B[i];
    }
    int hd=0,tl=0;
    for(int i=1;i<=n;++i) if(deg[i]==1)
    {
        q[tl++]=i;
    }
    int T=n,cnt=m;
    memset(dir,-1,sizeof(dir));
    while(T--)
    {
        int u=q[hd++]; vis[u]=1;
        // debug("%d\n",u);
        for(int i=head[u];~i;i=G[i].nex)
        {
            int v=G[i].to;
            if(--deg[v]==1) q[tl++]=v;
        }
        vector<int> E;
        for(int i=1;i<=cnt;++i) if(!mark[i])
        {
            if(a[i]==u&&b[i]==u)
            {
                // debug("e %d\n",i);
                dfs(i,0);
                continue;
            }
            if(b[i]==u) swap(a[i],b[i]),rev[i]^=1;
            if(a[i]==u) E.push_back(i);
        }
        int w=-1;
        for(int i=head[u];~i;i=G[i].nex)
        {
            int v=G[i].to;
            if(!vis[v]) {w=v; break;}
        }
        while(E.size())
        {
            if(E.size()==1)
            {
                int e=E[0];
                a[e]=w;
                break;
            }
            int x=E.back(); E.pop_back();
            int y=E.back(); E.pop_back();
            ++cnt; ch[cnt][0]=x,ch[cnt][1]=y;
            a[cnt]=b[y],b[cnt]=b[x];
            mark[x]=mark[y]=1;
            // debug("%d %d %d\n",u,x,y);
        }
        // debug("%d\n",u);
        // for(int i=1;i<=cnt;++i) if(!mark[i]) debug("%d %d\n",a[i],b[i]);
    }
    getdep(1);
    for(int i=1;i<=m;++i)
    {
        // debug("%d %d %d\n",i,rev[i],dir[i]);
        if(dir[i]) swap(A[i],B[i]);
        int u=A[i],v=B[i];
        while(dep[u]>dep[v]) upd(u,0),u=anc[u];
        while(dep[u]<dep[v]) upd(v,1),v=anc[v];
        while(u!=v)
        {
            upd(u,0),u=anc[u];
            upd(v,1),v=anc[v];
        }
    }
    printf("%d\n",an);
    for(int i=1;i<=m;++i)
    {
        printf("%d %d\n",A[i],B[i]);
    }
    return 0;
}

Measured memory_bytes: 512