best-restaurant-in-town-2

Anki started a new restaurant in Jalpaiguri. As a perfectionist, she wants no complaint from any of the customers.
So she decided to promise every customer with accurate time for waiting after the order is placed. Can you help Anki run her restaurant better by designing a program which will help her track the orders and hence calculate the accurate time?
But there is a problem. There are N types of dishes served there. For each item, the chef takes a certain time (varies from dish to dish) to prepare the dish and a stipulated time to rest after cooking it.

Note: Each customer orders only one dish.

Input format
The first line has a single integer T the number of test cases. Every test case comprises 4 lines.
First line contains N, C and R the no of dishes, the number of customers and relaxation time of the chef in seconds respectively.
Next line is followed by N integers signifying the preparation time for the i^th dish.
Next line contains C integers signifying the dish each customer ordered.
Next line contains the time of arrival of each customer in seconds considering the initial time to be 0. (i+1)^th customer does not arrive before i^th customer).

Note: All arrays have been treated to be 1-indexed.

Output format
Display C integers where each integer displays the time in seconds a customer has to wait for getting his dish cooked.

Constraints

1 ≤ T, N, C, R ≤ 100

SAMPLE INPUT
1
3 4 1
3 3 3
3 2 1 3
3 10 12 12

SAMPLE OUTPUT
3 3 5 9

Source: hackerearth | Difficulty: EASY
Tags: Ad-hoc

Implementation

Greedy algorithms


Solutions: