import io import sys from collections import defaultdict, deque, Counter from itertools import permutations, combinations, accumulate from heapq import heappush, heappop from bisect import bisect_right, bisect_left from math import gcd import math _INPUT = """\ 6 3 2 2 1 3 1 2 2 3 5 5 4 2 2 2 2 1 2 2 4 3 5 4 5 1 5 4 4 2 1 2 1 2 2 3 3 4 1 4 """ def Popcount(n): c = (n & 0x5555555555555555) + ((n>>1) & 0x5555555555555555) c = (c & 0x3333333333333333) + ((c>>2) & 0x3333333333333333) c = (c & 0x0f0f0f0f0f0f0f0f) + ((c>>4) & 0x0f0f0f0f0f0f0f0f) c = (c & 0x00ff00ff00ff00ff) + ((c>>8) & 0x00ff00ff00ff00ff) c = (c & 0x0000ffff0000ffff) + ((c>>16) & 0x0000ffff0000ffff) c = (c & 0x00000000ffffffff) + ((c>>32) & 0x00000000ffffffff) return c def input(): return sys.stdin.readline()[:-1] def solve(test): N,M,K=map(int, input().split()) X=list(map(lambda x:int(x)-1, input().split())) G=[[] for _ in range(N)] for _ in range(M): A,B=map(int, input().split()) G[A-1].append(B-1) G[B-1].append(A-1) C=[0]*K*(2**N)*N def idx(i,j,k): return i*(2**N)*N+j*N+k for i in range(K): C[idx(i,1<