import sys, math, itertools, functools, collections input = sys.stdin.readline #https://stackoverflow.com/questions/4798654/modular-multiplicative-inverse-function-in-python def egcd(a, b): if a == 0: return (b, 0, 1) else: g, y, x = egcd(b % a, a) return (g, x - (b // a) * y, y) def minv(a, m): g, x, y = egcd(a, m) if g != 1: raise Exception('modular inverse does not exist') else: return x % m def solve(testcase): n, w, d = map(int, input().split()) a = [*map(int, input().split())] g = math.gcd(d, w) d2 = d // g w2 = w // g modinv = minv(d2, w2) def solve(x): # Find the min y such that (d*y)%w == x # d*y = a*w+x # d2*y = a*w2+x2 if x%g: return 10**20 x //= g # d * y === x (mod w) # y = x * modinv(d) #print('solve', x, (x * pow(d2, -1, w2)) % w2) return (x * modinv) % w2 res = 0 for i in range(n//2): x, y = a[i], a[~i] res += min(solve((x-y)%w), solve((y-x)%w)) if res >= 10**20: res = 'IMPOSSIBLE' print('Case #'+str(testcase)+':', res) for testcase in range(1, int(input())+1): solve(testcase)