#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=2005;
vector<int> nxt[MAXN];
void ins(int x,int y){nxt[x].emplace_back(y);}
int n,m,fa[MAXN],in[MAXN],ot[MAXN],id;
void dfs(int x)
{
	in[x]=++id;
	for(auto p:nxt[x])if(p^fa[x])fa[p]=x,dfs(p);
	ot[x]=id;
}
bool intree(int x,int y){return in[x]>=in[y]&&in[x]<=ot[y];}//x in subtree y?
vector<pii> E;int dat[MAXN];
struct edge
{
	pii now;int px,py;
	edge(){}edge(pii _now,int _px,int _py){now=_now;px=_px;py=_py;}
}a[MAXN*2],A,B;int tp;
vector<int> newe,lin;
vector<pii> wr;
queue<int> li;int sum[MAXN];
bool ok[MAXN];
int main()
{
	n=read();m=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y);ins(y,x);++dat[x];++dat[y];
	}dfs(1);
	for(int i=1;i<=m;i++)
	{
		int x=read(),y=read();
		E.emplace_back(mp(x,y));
	}int ans=0;
	for(int i=1;i<=n;i++)
	{
		int cnt=0;
		for(auto p:E)if(intree(p.first,i)^intree(p.second,i))++cnt;
		ans+=min(2,cnt);sum[i]=cnt;
	}pr2(ans);for(int i=2;i<=n;i++)if(dat[i]==1)li.push(i);
	for(auto p:E)a[++tp]=edge(p,0,0),newe.emplace_back(tp);
	while(!li.empty())
	{
		int x=li.front();li.pop();
		if(ok[x]||sum[x]<=1)
		{
			--dat[fa[x]];
			if(dat[fa[x]]==1)li.push(fa[x]);continue;
		}lin.clear();int sz=0,id1,id2;
		for(auto p:newe)
		{
			if(intree(a[p].now.first,x)^intree(a[p].now.second,x))
			{
				if(sz==0)++sz,A=a[p],id1=p;
				else if(sz==1)++sz,B=a[p],id2=p;
				else lin.emplace_back(p);
			}
			else lin.emplace_back(p);
		}
		if(!intree(A.now.first,x))swap(A.now.first,A.now.second),swap(A.px,A.py);
		if(!intree(B.now.first,x))swap(B.now.first,B.now.second),swap(B.px,B.py);
		int u=x,pre;
		while(!intree(A.now.second,u)&&!intree(B.now.second,u))ok[u]=1,pre=u,u=fa[u];
		if(A.now.second==B.now.second)
		{
			swap(A.now.first,A.now.second);swap(A.px,A.py);
			a[id1]=A;a[id2]=B;
			newe.clear();for(auto p:lin)newe.emplace_back(p);
		}
		else
		{
			edge atom=edge(mp(A.now.second,B.now.second),id1,id2);newe.clear();
			a[++tp]=atom;newe.emplace_back(tp);for(auto p:lin)newe.emplace_back(p);
		}
		--dat[fa[x]];if(dat[fa[x]]==1)li.push(fa[x]);
	}
	for(int i=tp;i>=1;i--)
	{
		if(!a[i].px)wr.emplace_back(a[i].now);
		else
		{
			A=a[a[i].px];B=a[a[i].py];
			if(a[i].now.first!=A.now.first)swap(A.now.first,A.now.second),swap(A.px,A.py);
			if(a[i].now.second!=B.now.second)swap(B.now.second,B.now.first),swap(B.px,B.py);
			a[a[i].px]=A;a[a[i].py]=B;
		}
	}reverse(wr.begin(),wr.end());
	for(auto p:wr)pr1(p.first),pr2(p.second);
	return 0;
}


Measured memory_bytes: 640