#!/usr/bin/python3

from random import randint
from sys import setrecursionlimit
setrecursionlimit(10**6+47)

def sef(boss, v):
    if boss[v] == v: return v
    tmp = sef(boss, boss[v])
    boss[v] = tmp
    return tmp

def spoj(boss, u, v):
    bu = sef(boss, u)
    bv = sef(boss, v)
    if bu == bv: return
    if randint(0, 1): bu, bv = bv, bu
    boss[bu] = bv

def vyskusaj(N, K, orig_stupen, orig_boss):
    stupen = orig_stupen[:]
    boss = orig_boss[:]
    komponentov = len( set( boss ) )
    pridal_hrany = []
    krokov = 0
    kandidati = [ n for n in range(N) if stupen[n] < K ]
    while komponentov > 1 and krokov < min(100*N, 3000000) and len(kandidati) > 1:
        ix = randint(0, len(kandidati)-1)
        x = kandidati[ix]
        if stupen[x] == K:
            l = len(kandidati)
            kandidati[ix], kandidati[l-1] = kandidati[l-1], kandidati[ix]
            kandidati.pop()
            continue

        iy = randint(0, len(kandidati)-1)
        y = kandidati[iy]
        if stupen[y] == K:
            l = len(kandidati)
            kandidati[iy], kandidati[l-1] = kandidati[l-1], kandidati[iy]
            kandidati.pop()
            continue

        krokov += 1
        
        sx = sef(boss, x)
        sy = sef(boss, y)
        if sx == sy: continue
        
        komponentov -= 1
        spoj(boss, x, y)
        pridal_hrany.append( (x, y) )
        stupen[x] += 1
        stupen[y] += 1

    if komponentov == 1:
        return pridal_hrany
    else:
        return None

N, K, M = [ int(_) for _ in input().split() ]
stupen = [ 0 for n in range(N) ]
boss = [ n for n in range(N) ]
for m in range(M):
    x, y = [ int(_) for _ in input().split() ]
    stupen[x] += 1
    stupen[y] += 1
    spoj(boss, x, y)

if K == 0:
    if N == 1:
        print(0)
    else:
        print(-1)
    exit()

if K == 1:
    if N == 1:
        print(0)
    elif N == 2:
        if M == 0:
            print(1)
            print(0, 1)
        else:
            print(0)
    else:
        print(-1)
    exit()

pokusov = 100
if N > 10: pokusov = 14
if N > 100: pokusov = 1

for pokus in range(pokusov):
    odpoved = vyskusaj(N, K, stupen, boss)
    if odpoved is not None:
        print(len(odpoved))
        for x, y in odpoved: print(x, y)
        exit()

print(-1)
