P20500 [HackerEarth] There is a grid of n rows and m columns each cell containing a robot. Rows are numbered 0 to n-1 and columns 0 to m-1.
提高
题目描述

There is a grid of n rows and m columns each cell containing a robot. Rows are numbered 0 to n-1 and columns 0 to m-1.
Every robot has some initial energy associated with it which is equal to the number of distinct palindromes in its name. Some robots are connected with special connectors. Every morning these connectors generate some amount of energy and distribute it among the robots which are connected via this connector.
This is how it actually works-
Let two robots R1 with energy e1 and R2 with energy e2 are connected to each other, then the connector will generate energy e2 for robot R1 and energy e1 for robot R2 i.e final energy of robots R1 and R2 is e1+e2 both. On second day they both have energy 2*(e1+e2), as on 2nd day connector will use energies from the previous day not the initial energies.
Your task is to calculate the final energy (modulo 1000000007) of each robot after D days.
Two Robots can be connected to each other with multiple connectors.

INPUT -

First line contains two integers (n,m) ,size of grid.
Next n lines containing m space separated words(names of each robots).
Then one integer C(number of connectors)
Next C lines contains four integers(x1,y1,x2,y2) each i.e. robot at (x1,y1) is connected with robot at(x2,y2)
0 ≤ x1,x2 < n
0 ≤ y1,y2 < m
Last line contains one integer D.

OUTPUT-

n lines each containing m space separated integers i.e. final energy of each robot after D days modulo (10^9+7).

Constraints-

1 ≤ n,m ≤ 10

0 ≤ C ≤ 100

0 < D ≤ 1000000000

Robot names contains only lowercase (a-z) characters.

1 ≤ length of each robot name ≤ 10

SAMPLE INPUT
2 2
ab ba
cc da
3
0 0 1 1
0 0 1 1
1 0 1 1
4

SAMPLE OUTPUT
230 2
116 256

Explanation

Initial Energies
2 2
2 2

After day 1-
6 2
4 8

After Day 2-
22 2
12 24

After Day 3-
70 2
36 80

After Day 4-
230 2
116 256

输入格式

见题面

输出格式

见题面

样例输入
9 10 bcaedcac ddedaededc dabbeccbad dcabeacbc dbeaccbbad baaccdedad adacebbcdc bbdedeccca ceccbaace caadedad dadbbbeac dccbabede edebadee eddedcabea eceacddbc dabcbabb bbaeebcdd eceedcea abddddbd daeeaabcd cebdbbede ceeecacbd bcebbbce eaadcbcd aebbbdab cccbcdbbc ccbaaada ddbcbedcdc abdbaeee eabdeadae caeedeebb abdeeaabba deabbcdae bedbdcea bbeeedbde eecbcdda dabaebcdcd dcbdbbac eceaacccea beedacaad ecddabeb bebdbaaebc cbbceabdec bddadaeac cdeddcbc ceebcaad cbdcdddcc dbacdcdcb cbcebbceae baabadeed ccddcecd abcbacde cadacdceb abbeeeae ceaddeae abbdbdbbbb dddceabd dcddaedeb eebecccd ccbadbabbd abecebddc deebccbd cedccdee eccdccbe daedadbcb cdaecdedb beadedaed edccdeebdc acebdebc aaabbebeb cceabadaab bedadcebb adddebbba dddebcdaeb cadaacae eebcdded cacbcdbacd edaacdceb aeaeecdeb adabacccec bbdacddec cbaecddbe cddbcbaaea bbaaebcabe bbbabeebba dcbcbbdde dbbdcbce cceaebbead bddddedeb adbedbccac 100 2 5 3 4 1 5 4 2 6 5 1 4 4 8 7 3 8 5 6 7 1 8 7 8 8 6 0 2 0 0 4 3 5 2 1 0 8 0 6 8 2 5 5 4 4 3 1 0 7 2 0 5 5 5 3 9 4 6 2 0 8 0 6 4 2 6 0 3 6 9 3 0 5 9 1 8 7 3 8 6 6 8 8 6 8 6 0 3 8 7 6 7 3 1 5 5 2 5 4 9 5 1 4 0 0 9 6 4 4 9 6 1 6 8 4 8 6 0 0 2 0 0 5 8 5 2 0 3 6 9 2 3 1 3 8 3 1 5 5 3 4 8 6 4 7 4 7 2 0 7 7 4 4 9 3 4 2 3 3 5 6 8 7 6 4 3 3 4 8 7 3 8 1 7 5 0 1 5 3 8 6 3 7 4 0 6 4 6 4 7 7 1 2 6 0 5 8 3 4 7 0 1 6 6 1 9 8 7 3 5 1 5 8 8 1 2 2 4 1 6 5 4 7 2 0 0 6 1 8 9 1 5 8 1 1 7 3 4 1 2 3 3 8 3 3 7 7 3 2 6 6 4 5 8 0 2 8 8 3 9 7 1 5 4 6 2 0 9 4 0 0 0 8 4 4 5 6 8 2 6 7 8 4 4 2 7 3 3 4 3 6 8 5 2 1 4 0 1 2 6 8 1 5 5 3 6 0 0 3 6 5 4 2 0 1 1 4 9 6 3 7 2 3 4 0 5 7 7 5 6 2 4 4 2 5 6 1 4 4 5 7 7 2 2 6 4 3 5 5 3 0 2 2 9 7 7 5 4 0 7 0 7 8 9 7 2 2 9 0 2 8 5 5 3 3 7 5 9 7 7 1 6 8 2 8 6 2 2 5 9 5 6 5 4 8 4 6 2 4 7 993762782
样例输出
100101979 362041466 56401971 764983423 274847330 666049605 985139482 414132278