https://www.facebook.com/photo.php?fbid=737070220012527&set=g.163215593699283&type=1&theater&ifg=1
https://www.facebook.com/photo.php?fbid=737070210012528&set=g.163215593699283&type=1&theater&ifg=1
Input:
4 5
1 2 5 2 1
4 3 1 2 3
2 3 5 3 1
3 2 1 1 5
5
0 2 1
1 2 2 3 4
0 2 4
1 1 1 1 1
1 3 2 4 5
Output:
15
3
17