Problem C: Envelopes 

I have bought some greeting cards for my friends but in order to send them I must also buy some envelopes. Each card must be put inside a separate envelope without bending or tearing. The envelopes are made of so thin papers that one can put inside an envelope a card having even the same dimensions as that envelope.

Please help me choose envelopes so that the total amount I need to spend in buying them is minimized.


The input may contain multiple test cases.

The first line of each test case contains two integers M ( $1 \le M \le 5$) and N ( $M \le N \le 10$) where M is the number of greeting cards and N is the number of envelopes to choose from. The i­th ( $1 \le i \le M$) of the next M lines consists of two integers li and wi ( $1 \le l_i, w_i \le
50000$) giving the dimensions of the i­th greeting card. The i­th ( $1 \le
i \le N$) of the next N lines contains three integers Li, Wi and Ci ( $1 \le L_i, W_i, C_i \le 50000$) where Li and Wi give the dimensions of the i­th envelope and Ci is its price in Taka.

The input terminates with two zeros for M and N.


For each test case in the input first print the test case number on a separate line as shown in the sample output. If an envelope can be chosen for each of the greeting cards in the input, print one line for each where the i­th line contains the number of the envelope (in the order given in the input) inside which the i­th greeting card should be put. Otherwise, print ``cannot buy" on a line by itself. Note that if there are multiple solutions with minimum cost, any one of them is acceptable.

Print a blank line between two successive test cases.

Sample Input 

2 4
105 9
99 149
110 10 10
100 50 5
150 100 7
90 140 15
1 2
100 150
99 149 10
142 100 5
0 0

Sample Output 

Case #1
Case #2
cannot buy

Miguel Revilla