# 愚直チェック def popcnt(n): c = (n & 0x55555555) + ((n>>1) & 0x55555555) c = (c & 0x33333333) + ((c>>2) & 0x33333333) c = (c & 0x0f0f0f0f) + ((c>>4) & 0x0f0f0f0f) c = (c & 0x00ff00ff) + ((c>>8) & 0x00ff00ff) c = (c & 0x0000ffff) + ((c>>16) & 0x0000ffff) return c N = int(input()) if N > 20: print(1 // 0) A = [int(a) for a in input().split()] S = {} m = (1 << 60) - 1 for i in range(1 << N): s = 0 for j, a in enumerate(A): s |= a if i >> j & 1: s ^= m if s in S: S[s] = min(S[s], popcnt(i)) else: S[s] = popcnt(i) Q = int(input()) for a in [int(a) for a in input().split()]: print(S[a] if a in S else -1)