nmk = input()
n, m, k = list(int(i) for i in nmk.split())
roads = {}
soldiers = {}
spisok = []
for i in range(m):
    roads[i + 1] = list(int(i) for i in input().split())
for i in range(k):
    soldiers[i + 1] = list(int(i) for i in input().split())
defended = len(soldiers)
for position, health in soldiers.values():
    spisok.append(position)
    health_reset = health
    for a, b in roads.values():
        if position == a or position == b and health != 0:
            for j, p in roads.values():
                if health > 0:
                    print(a, b)
                    if a == p or a == j:
                        defended += 1
                        health -= 1
                        if a == p:
                            spisok.append(j)
                            a = j
                        else:
                            spisok.append(p)
                            a = p
                    elif b == p or b == j:
                        defended += 1
                        health -= 1
                        if b == p:
                            spisok.append(j)
                            b = j
                        else:
                            spisok.append(p)
                            b = p
                    else:
                        pass

                else:
                    break

print(defended)
print(spisok)
