QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 128 MB Total points: 100

#11059. Trains

Statistics

The Trains of Colour Parade begins tomorrow in Byteotia. Intense preparations are already in progress at the station's auxiliary tracks. There are $n$ parallel tracks at the station, numbered from $1$ to $n$. The train no. $i$ occupies the $i$-th track. Every train consists of $l$ cars and each car is painted with one of 26 colours (denoted by non-capital letters of the English alphabet). We say that two trains look the same, if their corresponding cars are painted the same colour.

Throughout the parade a crane will switch places of certain pairs of cars. The real parade, however, will take place tomorrow. Today the train dispatcher, Byteasar, watched the general rehearsal closely. He even wrote down the sequence of car swaps.

Byteasar particularly dislikes many trains looking the same. For each train $p$ he would like to calculate the maximum number of trains that at some moment look the same as the train $p$ at the very same moment.

Write a programme that:

  • reads descriptions of the trains occupying tracks and the sequence of car swaps,
  • for each train determines the maximum number of trains that look the same as it at certain moment,
  • writes out the result.

Input

The first line of the input contains three integers $n$, $l$ and $m$ ($2 ≤ n ≤ 1\,000$, $1 ≤ l ≤ 100$, $0 ≤ m ≤ 100\,000$), denoting respectively the number of trains, their common length and the number of car swaps. The following $n$ lines contain descriptions of the trains on successive tracks. The $k$-th line consists of $l$ small letters of the English alphabet denoting the colours of successive cars of the $k$-th train. Then $m$ lines describing the car swaps follow, in the order of the swaps. The $r$-th line contains four integers $p_1$, $w_1$, $p_2$, $w_2$ ($1 ≤ p_1,p_2 ≤ n$, $1 ≤ w_1,w_2 ≤ l$, $p_1≠p_2$ or $w_1≠w_2$) denoting the $r$-th car swap-the car no. w1 of the train no. $p_1$ is swapped with the car no. $w_2$ of the train no. $p_2$.

Output

Your programme should write out exactly $n$ lines. The $k$-th line should contain one integer-the number of trains looking the same as the train no. $k$ at certain moment.

Example

Input

5 6 7
ababbd
abbbbd
aaabad
caabbd
cabaad
2 3 5 4
5 3 5 5
3 5 2 2
1 2 4 3
2 2 5 1
1 1 3 3
4 1 5 6

Output

3
3
3
2
3

Hints

The figure presents the successive car swaps:


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
           (0)       (1)       (2)       (3)       (4)       (5)       (6)       (7)

The number of trains looking the same as either of the trains no. 1, 2 or 3 was maximal at time (4) (when all three looked the same). The number of trains looking the same as the train no. 5 was maximal at time (5) and (6). The number of trains looking the same as the train no. 4 was maximal at time (2).

About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.