#include<cassert>
//#include<deque>
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<string.h>
using namespace std;

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}
template<class T> struct Deque {
    vector<T> fr, bk;

    Deque() { }

    template<class Iter> Deque(Iter first, Iter last) : bk(first, last) {}

    size_t size() const {
	return fr.size() + bk.size();
    }

    bool empty() const {
	return fr.empty() && bk.empty();
    }

    T& operator[](size_t i) {
	if (i < fr.size()) return fr[fr.size() - 1 - i];
	return bk[i - fr.size()];
    }

    const T& operator[](size_t i) const {
	if (i < fr.size()) return fr[fr.size() - 1 - i];
	return bk[i - fr.size()];
    }

    T& back() {
	if (bk.empty()) return fr[0];
	return bk.back();
    }

    const T& back() const {
	if (bk.empty()) return fr[0];
	return bk.back();
    }

    void push_back(const T &t) {
	bk.push_back(t);
    }

    template<typename... Args>
    void emplace_back(Args&&... args) {
	bk.emplace_back(forward<Args>(args)...);
    }

    void pop_back() {
	if (bk.empty()) {
	    pop_back_helper(fr, bk);
	} else {
	    bk.pop_back();
	}
    }

    T& front() {
	if (fr.empty()) return bk[0];
	return fr.back();
    }

    const T& front() const {
	if (fr.empty()) return bk[0];
	return fr.back();
    }

    void push_front(const T &t) {
	fr.push_back(t);
    }

    template<typename... Args>
    void emplace_front(Args&&... args) {
	fr.emplace_back(forward<Args>(args)...);
    }

    void pop_front() {
	if (fr.empty()) {
	    pop_back_helper(bk, fr);
	} else {
	    fr.pop_back();
	}
    }

    void reverse() {
	swap(fr, bk);
    }

    static void pop_back_helper(vector<T> &fr, vector<T> &bk) {
	size_t s = fr.size();
	size_t t = (s-1)/2;
	bk.resize(t);
	for (size_t i=1; i<=t; i++) bk[t-i] = fr[i];
	for (size_t i=t+1; i<s; i++) fr[i-t-1] = fr[i];
	fr.resize(s-1-t);
    }

    struct iterator {
	using difference_type   = size_t;
	using value_type        = T;
	using pointer           = T*;
	using reference         = T&;
	using iterator_category = typename vector<T>::iterator::iterator_category;

	using sup_iter = typename vector<T>::iterator;

	sup_iter fr_it, bk_it;
	sup_iter fr_begin, bk_begin;

	iterator(sup_iter fr_it_, sup_iter bk_it_, sup_iter fr_begin_, sup_iter bk_begin_) {
	    fr_it = fr_it_;
	    bk_it = bk_it_;
	    fr_begin = fr_begin_;
	    bk_begin = bk_begin_;
	}

	iterator& operator=(const iterator &y) {
	    fr_it = y.fr_it;
	    bk_it = y.bk_it;
	    fr_begin = y.fr_begin;
	    bk_begin = y.bk_begin;
	    return *this;
	}

	iterator& operator++() {
	    if (fr_it == fr_begin) ++bk_it;
	    else --fr_it;
	    return *this;
	}

	iterator operator++(int) {
	    iterator tmp = *this;
	    ++*this;
	    return tmp;
	}

	iterator& operator--() {
	    if (bk_it == bk_begin) ++fr_it;
	    else --bk_it;
	    return *this;
	}

	iterator operator--(int) {
	    iterator tmp = *this;
	    --*this;
	    return tmp;
	}

	T& operator*() {
	    if (fr_it == fr_begin) return *bk_it;
	    else return *prev(fr_it);
	}

	T* operator->() {
	    if (fr_it == fr_begin) return bk_it;
	    else return prev(fr_it);
	}

	bool operator==(const iterator &y) const { return fr_it == y.fr_it && bk_it == y.bk_it; }
	bool operator!=(const iterator &y) const { return !(*this == y); }

	bool operator<(const iterator &y) const { return fr_it > y.fr_it || bk_it < y.bk_it; }
	bool operator>(const iterator &y) const { return y < *this; }
	bool operator<=(const iterator &y) const { return !(y < *this); }
	bool operator>=(const iterator &y) const { return !(*this < y); }

	size_t operator-(const iterator &y) const {
	    return (bk_it - y.bk_it) + (y.fr_it - fr_it);
	}

	iterator& operator+=(size_t k) {
	    size_t s = fr_it - fr_begin;
	    if (s >= k) {
		fr_it -= k;
	    } else {
		fr_it = fr_begin;
		bk_it += k-s;
	    }
	    return *this;
	}

	iterator operator+(size_t k) const {
	    iterator it = *this;
	    return it += k;
	}

	iterator& operator-=(size_t k) {
	    size_t s = bk_it - bk_begin;
	    if (s >= k) {
		bk_it -= k;
	    } else {
		bk_it = bk_begin;
		fr_it += k-s;
	    }
	    return *this;
	}

	iterator operator-(size_t k) const {
	    iterator it = *this;
	    return it -= k;
	}

    };

    iterator begin() {
	return iterator(fr.end(), bk.begin(), fr.begin(), bk.begin());
    }

    iterator end() {
	return iterator(fr.begin(), bk.end(), fr.begin(), bk.begin());
    }
};

int N, M;

VI G[2011];
int par[2011];
VI ord;
VI path(int s, int t) {
    par[t] = t;
    ord.clear();
    ord.push_back(t);
    REP (i_, N) {
	int v = ord[i_];
	EACH (e, G[v]) if (*e != par[v]) {
	    par[*e] = v;
	    if (*e == s) goto BREAK;
	    ord.push_back(*e);
	}
    }
BREAK:


    VI ret;
    while (1) {
	ret.push_back(s);
	if (s == t) break;
	s = par[s];
    }

    return ret;
}

struct Edge {
    Deque<int> dq;
    int parent;
    bool flip;
    bool order;
    bool fix;

    Edge(int u_, int v_) {
	VI p = path(u_, v_);
	dq = Deque<int>(p.begin(), p.end());
	parent = -1;
	flip = order = fix = false;
    }

    int u() const { return dq.front(); }
    int v() const { return dq.back(); }

    bool one_end(int x) const {
	return x == u() || x == v();
    }
};
vector<Edge> edges;

bool ban[2011];
int Eu[2011], Ev[2011];

void MAIN() {
    scanf("%d%d", &N, &M);
    REP (i, N-1) {
	int x, y;
	scanf("%d%d", &x, &y);
	x--; y--;
	G[x].push_back(y);
	G[y].push_back(x);
    }
    REP (i, M) {
	int u, v;
	scanf("%d%d", &u, &v);
	u--; v--;
	Eu[i] = u; Ev[i] = v;
	edges.emplace_back(u, v);
    }

    int ans = 0;
    {
	vector<pair<int, int> > g;
	REP (i, M) {
	    REP (j, edges[i].dq.size()-1u) {
		int x = edges[i].dq[j];
		int y = edges[i].dq[j+1];
		g.emplace_back(min(x, y), max(x, y));
	    }
	}
	sort(g.begin(), g.end());
	for (int i=0, j=0; i<(int)g.size(); i=j) {
	    while (j < (int)g.size() && g[i] == g[j]) {
		j++;
	    }
	    if (j-i >= 2) ans += 2;
	    else ans++;
	}
    }

    int rest = N;
    while (rest > 1) {
	int leaf = -1;
	REP (v, N) if (!ban[v]) {
	    int cnt = 0;
	    EACH (e, G[v]) if (!ban[*e]) {
		cnt++;
	    }
	    if (cnt == 1) {
		leaf = v;
		break;
	    }
	}

	VI Es;
	REP (i, edges.size()) if (!edges[i].fix && edges[i].one_end(leaf)) {
	    Es.push_back(i);
	    if (Es.size() == 2u) break;
	}

	if (Es.empty()) {
	} else if (Es.size() == 1u) {
	    int id = Es[0];
	    if (edges[id].u() == leaf) edges[id].dq.pop_front();
	    else edges[id].dq.pop_back();
	    if (edges[id].dq.size() == 1u) edges[id].fix = true;
	} else {
	    int a = Es[0], b = Es[1];
	    int ax = (edges[a].u() == leaf? edges[a].v(): edges[a].u());
	    int bx = (edges[b].u() == leaf? edges[b].v(): edges[b].u());

	    if (ax == bx) {
		if (edges[a].u() == leaf) edges[a].order = true;
		if (edges[b].v() == leaf) edges[b].order = true;
	    } else {
		edges[a].parent = edges.size();
		edges[b].parent = edges.size();
		if (edges[a].u() != ax) edges[a].flip = true;
		if (edges[b].v() != bx) edges[b].flip = true;
		edges.emplace_back(ax, bx);
	    }
	    edges[a].fix = true;
	    edges[b].fix = true;

	    REP (j, edges.size()) if (!edges[j].fix && edges[j].one_end(leaf)) {
		if (edges[j].v() == leaf) edges[j].dq.pop_back();
		else edges[j].dq.pop_front();

		if (edges[j].dq.size() == 1u) edges[j].fix = true;
	    }
	}
	rest--;
	ban[leaf] = true;
    }
    for (int i=edges.size(); i--;) {
//	if (!edges[i].fix) {
//	    printf("%d\n", i);
//	    rprintf("%d", edges[i].dq.begin(), edges[i].dq.end());
//	}
	assert(edges[i].fix);
	if (edges[i].parent != -1) {
	    edges[i].order = edges[edges[i].parent].order ^ edges[i].flip;
	}
    }

    printf("%d\n", ans);
    REP (i, M) {
	int u = Eu[i], v = Ev[i];
	if (edges[i].order) swap(u, v);
	printf("%d %d\n", u+1, v+1);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 22004