import itertools class Task: def run(self): N, M, X = map(int, input().split()) questions = [list(map(int, input().split())) for _ in range(N)] K = int(input()) C = list(map(int, input().split())) max_satisfy_score = 0 for ptn in itertools.permutations(questions): satisfy_score_sum = 0 for c in C: answered = ptn[:c] quality_sum = sum([q for q, g in answered]) number_of_genre = len(set([g for q, g in answered])) satisfy_score = quality_sum + X * number_of_genre satisfy_score_sum += satisfy_score if max_satisfy_score < satisfy_score_sum: max_satisfy_score = satisfy_score_sum print(max_satisfy_score) if __name__ == "__main__": task = Task() task.run()