You are given a two-dimensional array of integers of size N×K, A = A_0,0, A_0,1, …, A_0,K−1, A_1,0, …, A_N−1,K−1 and also arrays of integers of size M, U = U_0, …, U_M−1 and V = V_0, …, V_M−1.
Jimin made a cute weighted undirected graph G, which is a complete graph with the weight of an edge connecting vertices u and v is A_u,(v,mod,K)−A_v,(u,mod,K). Eunsoo then found the minimum spanning tree of G.
However, Jongyoung brutally deleted edges of G connecting U_i and V_i for 0≤i≤M−1. Note that G may not be connected after deleting the edges.
Now, to help poor Jimin and Eunsoo, you should find the minimum spanning forest of G. A minimum spanning forest is a union of the minimum spanning trees of its connected components.
The first line contains three space-separated integers, N, K, and M.
Each of the following N lines contains K space-separated integers, A_i,0, …, A_i,K−1. (0≤i≤N−1)
Each of the following M lines contains two space-separated integers, U_i and V_i. (0≤i≤M−1)
Output the sum of the weight of edges in the minimum spanning forest of G.