N,M,X = map(int, input().split(" ")) questions = [] for i in range(N): questions.append(list(map(int, input().split(" ")))) K = int(input()) num_answers = list(map(int, input().split(" "))) def calc_confident(question_list, num_answers, X): sum = 0 for num in num_answers: janru = set() for i in range(num): janru.add(question_list[i][1]) sum += question_list[i][0] sum += len(janru)*X return sum def get_max(sorted_list, now_list, N, X): #sorted_list = sorted(questions, key= lambda x:-x[0]) if not now_list: return sorted_list[0] j_set = set([j[1] for j in now_list]) n_j = len(j_set) if n_j == N: return sorted_list[0] max_q = sorted_list[0] other_j_list = [s for s in sorted_list if s[1] not in j_set] if not other_j_list: return max_q max_q_j = other_j_list[0] if max_q == max_q_j: return max_q dif = max_q[0] - max_q_j[0] if dif > X: return max_q else: return max_q_j questions = sorted_list = sorted(questions, key= lambda x:-x[0]) now_list = [] for i in range(len(questions)): max_q =get_max(questions, now_list, N,X) now_list.append(max_q) questions.remove(max_q) val = calc_confident(now_list, num_answers, X) print(val)