Problem: problem

You are playing with J using the Midakuji. The Amida lottery consists of n vertical bars and m horizontal bars. The vertical bars are numbered from 1 to n in order from the left, and the vertical bar i The positive integer si is written at the bottom of.

<image>

Figure 3-1 Example of Amidakuji (n = 4, m = 5, s1 = 20, s2 = 80, s3 = 100, s4 = 50)

The integer written at the bottom of the vertical bar i, which is reached by following the path from the top of the vertical bar i, is the score when the vertical bar i is selected. For example, in Fig. 3-1 the vertical bar 1 is selected. And the score is 80 points, and if the vertical bar 2 is selected, the score is 100 points.

<image>

Figure 3-2 Example of how to follow the road

Mr. J decides to choose a series of k books from vertical bar 1 to vertical bar k. The total score when selecting those k vertical bars is J's score. However, you are in the Amidakuji You can select one horizontal bar and delete that horizontal bar from the Amidakuji. (You do not have to delete it.) If you delete one horizontal bar, the vertical bar in the deleted Amidakuji will be displayed vertically. J's score is the total of the points when selecting k consecutive vertical bars from bar 1 to vertical bar k.

Given the shape of the Amida lottery and the number of vertical bars k that J chooses as input, create a program that finds the minimum value of J's score.



input

The input consists of multiple datasets. Each dataset is given in the following format.

On the first line, four integers n, m, h, k are written separated by blanks. N (2 ≤ n ≤ 1000) is the number of vertical bars, and m (1 ≤ m ≤ 100000) is the horizontal bar. H (2 ≤ h ≤ 1000) represents the length of the vertical bar, and k (1 ≤ k ≤ n) represents the number of vertical bars you choose.

The following n lines contain the score written at the bottom of the vertical bar. The first line (1 ≤ i ≤ n) contains the positive integer si. Also, s1 + s2 + ... + sn ≤ 2000000000 = 2 × 109.

The following m lines indicate the position of the horizontal bar. The horizontal bars are numbered from 1 to m. The first line (1 ≤ i ≤ m) is the horizontal bar i. The two integers ai, bi (1 ≤ ai ≤ n --1, 1 ≤ bi ≤ h --1) representing the position are separated by blanks, and the horizontal bar i connects the vertical bar ai and the vertical bar ai + 1. , Indicates that the distance from the top edge of the horizontal bar i is bi. However, no two horizontal bars share an endpoint.

Of the scoring data, 20% of the points will have the lowest score for Mr. J if the horizontal bar is not deleted. Also, 30% of the points will satisfy n ≤ 20, m ≤ 30, h ≤ 10. 60% of the points are m ≤ 1000.

The end of the input is indicated by a line containing four zeros. The number of datasets does not exceed 10.

output

For each dataset, output the minimum score of Mr. J on one line.

Examples

Input

4 5 7 2
20
80
100
50
1 1
2 6
2 3
1 5
3 1
2 2 5 1
10
20
1 1
1 3
0 0 0 0


Output

100
10


Input

None


Output

None

Solution (in CPP):

Solution:
#include <cstdio>
#include <vector>

typedef std::pair<int,int> P;

int N, M, H, K;
int ps[1001];
std::vector<P> bars;
bool hasBar[1000][1000];
int r1[1000][1001], r2[1001][1001], r3[1000][1001];

int main(){
    while(scanf("%d %d %d %d", &N, &M, &H, &K), N || M || H || K){
        bars.clear();
        for(int i=1;i<H;i++){
            for(int j=1;j<N;j++){
                hasBar[i][j] = false;
            }
        }
        
        for(int i=1;i<=N;i++){
            scanf("%d", ps+i);
        }

        for(int i=0;i<M;i++){
            int a, b;
            scanf("%d %d", &a, &b);

            bars.push_back(std::make_pair(a, b));
            hasBar[b][a] = true;
        }

        for(int i=1;i<=N;i++){
            r1[0][i] = i;
            r2[H][i] = i;
        }

        for(int i=1;i<H;i++){
            for(int j=1;j<=N;j++){
                r3[i][j] = j;
            }
        
            for(int j=1;j<N;j++){
                if(hasBar[i][j]){std::swap(r3[i][j], r3[i][j+1]);}
            }

            for(int j=1;j<=N;j++){
                r1[i][j] = r3[i][r1[i-1][j]];
            }
        }

        for(int i=H-1;i>=1;i--){
            for(int j=1;j<=N;j++){
                r2[i][j] = r2[i+1][r3[i][j]];
            }
        }

        int res = 0;
        for(int i=1;i<=K;i++){
            res += ps[r1[H-1][i]];
        }

        for(const P& p : bars){
            int sum = 0;
            std::swap(r3[p.second][p.first], r3[p.second][p.first+1]);
            for(int i=1;i<=K;i++){
                sum += ps[r2[p.second+1][r3[p.second][r1[p.second-1][i]]]];
            }
            res = std::min(res, sum);
            std::swap(r3[p.second][p.first], r3[p.second][p.first+1]);
        }

        printf("%d\n", res);
    }
}