Two-Area Database

No attempts yetTime limit1sMemory limit256 MB

Problem

A database keeps its data in two areas. Area0 holds every kind of data. Area1 holds exactly one kind at a time.

Reading the ii-th kind of data from Area0 costs cic_i. Reading the data currently held in Area1 costs nothing.

You may pick any one kind of data in Area0 and copy it into Area1. The copy costs cc whichever kind you pick, and it erases whatever Area1 held before. You may copy at any moment and as many times as you want, and a copy leaves Area0 unchanged.

The kinds of data to read today and their order are fixed in advance and are all given to you. Area1 starts empty.

Find the smallest total cost of reading all of the data in the given order.

Input

The first line contains the number of test cases TT.

The first line of each test case contains three integers separated by spaces: the number of reads to perform today nn (1n1000001 \le n \le 100\,000), the number of kinds of data mm (1m301 \le m \le 30), and the cost cc (0c10000 \le c \le 1\,000) of copying one piece of data from Area0 into Area1.

The second line contains mm integers c1,c2,,cmc_1, c_2, \dots, c_m (1ci1001 \le c_i \le 100) separated by spaces. cic_i is the cost of reading the ii-th kind of data from Area0.

The third line contains nn integers d1,d2,,dnd_1, d_2, \dots, d_n (1dim1 \le d_i \le m) separated by spaces. did_i is the kind of data that must be read ii-th.

At the start every kind of data is stored in Area0 and Area1 is empty.

Output

For each test case, print the minimum cost of reading all of the data in order, one answer per line.