UPDATEIT - Update the array !

You have an array containing n elements initially all 0. You need to do a number of update operations on it. In each update you specify l, r and val which are the starting index, ending index and value to be added. After each update, you add the 'val' to all elements from index l to r. After 'u' updates are over, there will be q queries each containing an index for which you have to print the element at that index.

Input

First line consists of t, the number of test cases. (1 <= t <= 10)

Each test case consists of "n u", number of elements in the array and the number of update operations, in the first line (1 <= n <= 10000 and 1 <= u <= 100000)

Then follow u lines each of the format "l r val" (0 <= l, r < n, 0 <= val <=10000)

Next line contains q, the number of queries. (1 <= q <= 10000)

Next q lines contain an index (0 <= index < n)

Output

For each test case, output the answers to the corresponding queries in separate lines.

Example

Input:
1
5 3
0 1 7
2 4 6
1 3 2
3
0
3
4

Output:
7
8
6

Added by:Pandian
Date:2013-10-15
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own

hide comments
2016-08-01 16:56:46
simple BIT.
2016-07-28 20:24:00
easy and fun!
2016-07-25 05:16:04
@jainromil26
I think using "bit" is using "Binary Indexed Tree(BIT)".
Do you know binary indexed tree? If you don't know, please check on the Internet!
2016-07-16 08:44:24 Romil Jain
Solved without using bit. O(n) solution.
Someone please give a hint how to use bit?
2016-07-12 18:20:21
My 100th on SPOJ! Used BIT. ;)
2016-06-27 14:12:30
no need of segment tree!!! and BIT
2016-06-27 14:09:06
yeee....USE FAST I/O scanf(),printf() in c...
2016-06-18 19:54:22
Learnt something new !!!
2016-05-27 13:10:04 KD
learned something new :P
2016-05-18 17:29:12
TLE when using Segmented Tree + lazy propagation !
AC -> O(n) ...Prefix sum
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.