Trains

No attempts yetTime limit1sMemory limit128 MB

Problem

The Trains of Colour Parade opens tomorrow in Byteotia, and the crews are already busy on the station's auxiliary tracks. The station has nn parallel tracks numbered from 11 to nn, and train number ii stands on track ii. Every train is made of ll cars, and each car is painted in one of 2626 colours, written as a lowercase letter of the English alphabet. Two trains look the same when their cars match colour for colour in every position.

During the rehearsal a crane keeps swapping pairs of cars. The dispatcher watched the whole rehearsal and wrote down the sequence of swaps. He dislikes seeing many identical trains, so for every train pp he wants to know the largest number of trains (train pp included) that look the same as pp at one and the same moment.

Write a program that:

  • reads the initial trains and the sequence of car swaps,
  • for each train finds the maximum number of trains that look the same as it at some single moment,
  • prints those numbers.

Input

The first line holds three integers nn, ll, and mm (2n1,0002 \le n \le 1{,}000, 1l1001 \le l \le 100, 0m100,0000 \le m \le 100{,}000): the number of trains, their common length, and the number of car swaps. Each of the next nn lines holds a string of ll lowercase letters; the kk-th of these lines gives the colours of the cars of the train on track kk, from the first car to the last. Each of the following mm lines describes one swap, given in the order the swaps happen. A swap line holds four integers p1p_1, w1w_1, p2p_2, w2w_2 (1p1,p2n1 \le p_1, p_2 \le n, 1w1,w2l1 \le w_1, w_2 \le l, with p1p2p_1 \ne p_2 or w1w2w_1 \ne w_2): car w1w_1 of train p1p_1 is exchanged with car w2w_2 of train p2p_2.

Output

Print exactly nn lines. The kk-th line holds one integer: the maximum number of trains (train kk included) that look the same as train kk at some single moment, taken over the initial arrangement and every arrangement right after a swap.

Note

The diagram below shows the cars being swapped step by step. The numbers (0)(0) through (7)(7) mark the initial state and the state right after each swap.

time      (0)     (1)     (2)     (3)     (4)     (5)     (6)     (7)
track 1   ababbd  ababbd  ababbd  ababbd  aaabbd  aaabbd  aaabbd  aaabbd
track 2   abbbbd  ababbd  ababbd  aaabbd  aaabbd  acabbd  acabbd  acabbd
track 3   aaabad  aaabad  aaabad  aaabbd  aaabbd  aaabbd  aaabbd  aaabbd
track 4   caabbd  caabbd  caabbd  caabbd  cabbbd  cabbbd  cabbbd  dabbbd
track 5   cabaad  cabbad  caabbd  caabbd  caabbd  aaabbd  aaabbd  aaabbc

For trains 11, 22, and 33 the largest matching group appears at time (4)(4), when all three read aaabbd. Train 55 reaches its maximum at times (5)(5) and (6)(6). Train 44 reaches its maximum at time (2)(2), when tracks 44 and 55 both read caabbd.