This page is still under construction.

Parts of this page are still being built. What you see may change.

Civil Engineering

Time limit1sMemory limit128 MB

Summary
Read material densities and oblong dimensions, then sum each oblong's volume times its material density for each data set.
Level

Easy2 of 10

Topics
Implementation, Math, Array, Brute force
Solved
No attempts yet

Problem

Civil engineering is concerned with how to build structures so that they do not collapse (whereas architects care more about how things look). Such structures include buildings in an earthquake-prone area, or dams in a hurricane-prone area. Here we look at a simple problem related to building construction.

Suppose you want to place a building on a plot of land, but you have a limit on the building's total weight. Checking whether a proposed construction exceeds that weight can be quite a chore, so we ask you to write a program that takes care of it for civil engineers.

The building is described as a collection of oblongs (rectangular 3-dimensional blocks) that are assembled to form the building. Each oblong comes with its dimensions (height, width, depth) and the material it is made from. In addition, for each material you are given its density (weight per unit volume). Compute the total weight of all the oblongs.

Input

The first line contains an integer K≥1K \ge 1, the number of data sets. Then follow KK data sets, each of the following form.

The first line of a data set contains two integers mm and nn (both between 11 and 1000010000): mm is the number of materials in the database, and nn is the number of oblongs in the building.

The next mm lines each contain the density of one material, a non-negative integer in grams per cubic centimeter.

The next nn lines each contain four integers hh, ww, dd, ii: the height, width, and depth of an oblong (in centimeters), and the index ii of its material. hh, ww, dd are non-negative integers, and ii is an integer between 11 and mm.

For every input it is guaranteed that the total weight fits in a signed 32-bit integer.

Output

For each data set, first output a line "Data Set x:" by itself, where xx is the data set number (starting from 11). Then, on the next line, output the total weight of the oblongs in grams.

Examples3

  1. Example 1

    Input
    1
    3 4
    2
    4
    10
    30 50 49 3
    10 50 49 1
    25 50 2 3
    25 2 49 3
    
    Expected output
    Data Set 1:
    833500
    
  2. Example 2

    Input
    2
    1 1
    5
    2 3 4 1
    2 2
    1
    3
    1 1 1 1
    2 2 2 2
    
    Expected output
    Data Set 1:
    120
    Data Set 2:
    25
    
  3. Example 3

    Input
    1
    1 3
    2
    1 1 1 1
    2 2 2 1
    3 3 3 1
    
    Expected output
    Data Set 1:
    72