#include <cstdio>
#include <vector>
#include <utility>
#include <unordered_set>
#include <chrono>
using namespace std;
typedef pair<int,int> ii;

struct custom_hash {
    typedef long long ll;
    typedef unsigned long long ull;
    const ull FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    static ull splitmix64(ull x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(ll x) const {
        return splitmix64(x + FIXED_RANDOM);
    }
    size_t operator()(const pair<int,int> &i)const{
        return splitmix64((((ll)i.first)^(((ll)i.second)<<32))+FIXED_RANDOM);
    }
};


struct ufds{
    int p[2005];
    
    ufds(){
        for (int x=0;x<2005;x++){
            p[x]=x;
        }
    }
    
    int parent(int i){return (p[i]==i)?i:p[i]=parent(p[i]);}
} dsu=*new ufds();

int n,k;
vector<int> al[2005];
int parent[2005];
int depth[2005];
vector<int> edges[2005];
int deg[2005];

ii path[2005];

vector<int> proc;

unordered_set<int,custom_hash> s;

void dfs(int i,int p){
    if (p!=-1) proc.push_back(i);
    for (auto &it:al[i]){
        if (it==p) continue;
        parent[it]=i;
        depth[it]=depth[i]+1;
        dfs(it,i);
    }
}

void process(int i,int j,int k){
    if (depth[i]<depth[j]) swap(i,j);
    
    while (depth[i]!=depth[j]){
        edges[i].push_back(k);
        i=parent[i];
    }
    
    while (i!=j){
        edges[i].push_back(k);
        i=parent[i];
        edges[j].push_back(k);
        j=parent[j];
    }
}

bool dir(int __i,int __j){
    unordered_set<ii,custom_hash> dir;
    
    int i=path[__i].first,j=path[__i].second;
    
    while (depth[i]>depth[j]){
        dir.insert(ii(i,parent[i]));
        i=parent[i];
    }
    
    while (depth[i]<depth[j]){
        dir.insert(ii(parent[j],j));
        j=parent[j];
    }
    
    while (i!=j){
        dir.insert(ii(i,parent[i]));
        i=parent[i];
        dir.insert(ii(parent[j],j));
        j=parent[j];
    }
    
    i=path[__j].first,j=path[__j].second;
    while (depth[i]>depth[j]){
        if (dir.count(ii(i,parent[i]))) return true;
        i=parent[i];
    }
    
    while (depth[i]<depth[j]){
        if (dir.count(ii(parent[j],j))) return true;
        j=parent[j];
    }
    
    while (i!=j){
        if (dir.count(ii(i,parent[i]))) return true;
        i=parent[i];
        if (dir.count(ii(parent[j],j))) return true;
        j=parent[j];
    }
    
    return false;
}

vector<int> al2[2005];
bool state[2005];
bool visited[2005];

void dfs(int i){ 
    visited[i]=true;
    for (auto &it:al2[i]){
        if (visited[it]) continue;
        state[it]=state[i]^dir(i,it);
        dfs(it);
    }
}

int main(){
    scanf("%d%d",&n,&k);
    
    int a,b;
    for (int x=1;x<n;x++){
        scanf("%d%d",&a,&b);
        al[a].push_back(b);
        al[b].push_back(a);
    }
    
    dfs(1,-1);
    
    for (int x=0;x<k;x++){
        scanf("%d%d",&path[x].first,&path[x].second);
        process(path[x].first,path[x].second,x);
    }
    
    int __ans=0;
    
    int node;
    while (!proc.empty()){
        node=proc.back(),proc.pop_back();
        if (edges[node].size()==1){
            __ans++;
        }
        else if (edges[node].size()>=2){
            __ans+=2;
            s.clear();
            for (auto &it:edges[node]){
                s.insert(dsu.parent(it));
            }
            
            if (s.size()==edges[node].size()){
               int temp=edges[node][0],temp2=edges[node][1];
               dsu.p[temp]=temp2;   
               al2[temp].push_back(temp2);
               al2[temp2].push_back(temp);
               
               //printf("%d %d %d\n",temp,temp2,dir(temp,temp2));
            }
        }
    }
    
            
    printf("%d\n",__ans);    
    for (int x=0;x<k;x++){
        if (!visited[x]) dfs(x);
        if (state[x]) printf("%d %d\n",path[x].first,path[x].second);
        else printf("%d %d\n",path[x].second,path[x].first);
    }
}

Measured memory_bytes: 7040