#include <bits/stdc++.h>
using namespace std;
const int Maxn=2005;
int d[Maxn];
set<int>e[Maxn];
vector<int>q[Maxn],bak[Maxn];
map<pair<int,int>,int>val;
struct node{
    int s,t,a,b,del,son,rev;
}w[Maxn*Maxn];
bool dfs(int x,int fa,int t){
    if(x==t)return true;
    for(int y:e[x]){
        if(y==fa)continue;
        if(dfs(y,x,t))return ++val[minmax(x,y)];
    }
    return false;
}
set<pair<int,int>>EEE;
bool dfs2(int x,int fa,int t){
    if(x==t)return true;
    for(int y:bak[x]){
        if(y==fa)continue;
        if(dfs2(y,x,t))return EEE.emplace(x,y),true;
    }
    return false;
}
void check(int m,int ans){
    for(int i=1;i<=m;i++)
        dfs2(w[i].s,0,w[i].t);
    cerr<<"excepted="<<ans<<" get="<<EEE.size()<<"\n";
    if(ans!=EEE.size())cerr<<"failed\n",exit(1);
    else cerr<<"success\n";
}
int main(){
    // freopen("data.in","r",stdin);
    int n,m;scanf("%d%d",&n,&m);
    int cnt=m;
    for(int i=1;i<n;i++){
        int x,y;scanf("%d%d",&x,&y);
        bak[x].push_back(y);
        bak[y].push_back(x);
        e[x].insert(y);
        e[y].insert(x);
    }
    for(int i=1;i<=m;i++){
        scanf("%d%d",&w[i].s,&w[i].t);
        // cerr<<"i="<<i<<" s="<<w[i].s<<" t="<<w[i].t<<"\n";
        q[w[i].s].push_back(i);
        q[w[i].t].push_back(i);
        dfs(w[i].s,0,w[i].t);
        w[i].a=w[i].s;w[i].b=w[i].t;
    }
    queue<int>Q;
    for(int i=1;i<=n;i++)d[i]=e[i].size();
    for(int i=1;i<=n;i++)
        if(d[i]==1)
            Q.push(i);
    mt19937 rnd((size_t)new char);
    while(Q.size()){
        int x=Q.front();Q.pop();
        // cout<<"x="<<x<<"\n";
        if(!e[x].size())continue;
        int y=*e[x].begin();
        // cout<<"y="<<y<<"\n";
        e[y].erase(x);
        e[x].erase(y);
        if(--d[y]<=1)Q.push(y);
        if(!q[x].size())continue;
        auto get=[&](){
            while(q[x].size()&&w[q[x].back()].del)q[x].pop_back();
            if(!q[x].size())return 0;
            int ret=q[x].back();q[x].pop_back();
            return ret;
        };
        while(1){
            int a=get();
            int b=get();
            // cout<<"\tcollect;a="<<a<<" b="<<b<<"\n";
            if(!a)break;
            if(!b){
                assert(w[a].a==x||w[a].b==x);
                int u=w[a].a^w[a].b^x;
                // cout<<"\t\tid="<<a<<" s="<<w[a].s<<" t="<<w[a].t<<" a="<<w[a].a<<" b="<<w[a].b<<"\n";
                if(u==y){
                    w[a].del=true;
                }else{
                    (x==w[a].a?w[a].a:w[a].b)=y;
                    q[y].push_back(a);
                }
            }else{
                assert(w[a].a==x||w[a].b==x);
                assert(w[b].a==x||w[b].b==x);
                int u=w[a].a^w[a].b^x;
                int v=w[b].a^w[b].b^x;
                cnt++;
                w[cnt].s=w[cnt].a=u;
                w[cnt].t=w[cnt].b=v;
                w[a].son=cnt;
                w[b].son=cnt;
                if(w[a].a!=x)w[a].rev^=1;
                if(w[b].a!=x)w[b].rev^=1;
                w[a].rev^=1;
                if(u!=v){
                    q[u].push_back(cnt);
                    q[v].push_back(cnt);
                }
                w[a].del=1;
                w[b].del=1;
                // cout<<"\t\tid="<<a<<" s="<<w[a].s<<" t="<<w[a].t<<" a="<<w[a].a<<" b="<<w[a].b<<" rev="<<w[a].rev<<"\n";
                // cout<<"\t\tid="<<b<<" s="<<w[b].s<<" t="<<w[b].t<<" a="<<w[b].a<<" b="<<w[b].b<<" rev="<<w[b].rev<<"\n";
                // cout<<"\t\tnew="<<cnt<<" s="<<w[cnt].s<<" t="<<w[cnt].t<<" a="<<w[cnt].a<<" b="<<w[cnt].b<<"\n";
            }
        }
    }
    int ans=0;
    for(auto i:val)ans+=min(i.second,2);
    for(int i=cnt;i>=1;i--){
        if(w[i].son)w[i].rev=w[w[i].son].rev^w[i].rev;
        if(w[i].rev)swap(w[i].s,w[i].t);
    }
    cout<<ans<<"\n";
    for(int i=1;i<=m;i++)
        cout<<w[i].s<<" "<<w[i].t<<"\n";
    return 0;
    check(m,ans);
    cerr<<"finished\n";
    return 0;
}

Measured memory_bytes: 1152