import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) b = 10 ** 9 + 7 def test(): x, y = map(int, input().split()) m = int(input()) A = sorted(map(int, input().split())) dp = {x * b + y} for i, a in enumerate(A): ndp = set() for xy in dp: x, y = divmod(xy, b) if x - a >= 0: ndp.add((x - a) * b + y) if y - a >= 0: ndp.add(x * b + y - a) if not ndp: return i dp = ndp return m d = int(input()) print(*[test() for _ in range(d)], sep="\n")