def calc_cost(): a = int(10 ** 7 / supporter ** 0.5 + 2) while supporter * a ** 2 > 10 ** 14: a -= 1 return a def execute(key, param = None): global supporter, money if key == 2: supporter += 1 elif key == 3: money += 50000 from random import randrange N, T = map(int, input().split()) supporter = 1 money = 10 ** 6 for _ in range(N): a, b, c, d = map(int, input().split()) M = 14 done = [[[0] * M for _ in range(M - 1)], [[0] * (M - 1) for _ in range(M)]] for _ in range(T): u, v = map(int, input().split()) cost = calc_cost() print("cost =", cost, "u, v =", u, v) if money >= cost: while 1: t = randrange(2) if t == 0: i = randrange(M - 1) j = randrange(M) else: i = randrange(M) j = randrange(M - 1) if done[t][i][j] == 0: done[t][i][j] = 1 break if t == 0: ni, nj = i + 1, j else: ni, nj = i, j + 1 execute(1, i + 1, j + 1, ni + 1, nj + 1) else: execute(2)