for _ in range(int(input())):
J, N = map(int, input().split())
lst = []
for i in range(N):
r, c = map(int, input().split())
lst.append(r*c)
lst.sort(reverse=True)
cnt = 0
while J > 0:
J -= lst[cnt]
cnt += 1
print(cnt)