#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=2010, LOG=20;

int n, m, ted, k, u, v, x, y, t, a, b, ans;
int A[MAXN*2], B[MAXN*2], out[MAXN*2][2];
bool dead[MAXN];
int deg[MAXN];
int par[MAXN], h[MAXN], sum[MAXN];
int lca[MAXN][MAXN];
vector<int> G[MAXN], vec[MAXN];

void dfs1(int node){
	h[node]=h[par[node]]+1;
	for (int v:G[node]) if (v!=par[node]) par[v]=node, dfs1(v);
}
int Lca(int x, int y){
	if (x==y) return x;
	if (h[x]<h[y]) swap(x, y);
	if (lca[x][y]) return lca[x][y];
	return lca[x][y]=Lca(par[x], y);
}
int dfs2(int node){
	for (int v:G[node]) if (v!=par[node]) sum[node]+=dfs2(v);
	return sum[node];
}

void Solve(){
//	debug("FUCK")
	int v=0, u;
	for (int i=1; i<=n && !v; i++) if (deg[i]==1) v=i;
	if (!v) return ;
	dead[v]=1;
	for (int i:G[v]) if (!dead[i]) u=i;
	deg[u]--;
	deg[v]--;
	sort(all(vec[v]));
	vector<int> tmp;
	for (int x:vec[v]){
		if (tmp.empty() || tmp.back()!=x) tmp.pb(x);
		else tmp.pop_back();
	}
	
//	debug2(v, u)
//	debugv(tmp)
	
	if (tmp.size()==0){
		Solve();
		return ;
	}
	int is2=0, x, y, id, X, Y;
	if (tmp.size()>=2){
		x=tmp.back();
		tmp.pop_back();
		y=tmp.back();
		tmp.pop_back();
		is2=1;
	}
	
	if (is2){
		id=++ted;
		A[id]=X=(A[x]^B[x]^v);
		B[id]=Y=(A[y]^B[y]^v);
		vec[X].pb(id);
		vec[Y].pb(id);
		vec[X].pb(x);
		vec[Y].pb(y);
	}
	
	vector<int> shit;
	for (int i=0; i<tmp.size(); i++){
		int id=tmp[i];
		if (A[id]==v) A[id]=u;
		if (B[id]==v) B[id]=u;
		vec[u].pb(id);
		if (A[id]==B[id]) out[id][0]=u, out[id][1]=v, shit.pb(0);
		else shit.pb(1);
	}
	Solve();
	if (is2){
		if (out[id][0]==X){
			out[x][0]=X;
			out[x][1]=v;
			out[y][0]=v;
			out[y][1]=Y;
		}
		else{
			out[y][0]=Y;
			out[y][1]=v;
			out[x][0]=v;
			out[x][1]=X;
		}
	}
	for (int i=0; i<tmp.size(); i++){
		if (shit[i]){
			int id=tmp[i];
			if (out[id][0]==u) out[id][0]=v;
			if (out[id][1]==u) out[id][1]=v;
		}
	}
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m;
	for (int i=1; i<n; ++i){
		cin>>u>>v;
		G[u].pb(v);
		G[v].pb(u);
		deg[u]++;
		deg[v]++;
	}
	dfs1(1);
	for (int i=1; i<=m; i++){
		cin>>A[i]>>B[i];
		vec[A[i]].pb(i);
		vec[B[i]].pb(i);
		sum[A[i]]++;
		sum[B[i]]++;
		sum[Lca(A[i], B[i])]-=2;
	}
	dfs2(1);
	for (int i=2; i<=n; i++) ans+=min(sum[i], 2);
	ted=m;
	Solve();
	cout<<ans<<"\n";
	for (int i=1; i<=m; i++) cout<<out[i][0]<<" "<<out[i][1]<<"\n";
	
	return 0;
}


Measured memory_bytes: 19924