#include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; const int INF = 0x3f3f3f3f, N = 500, M = 1000000; struct EG { int a, b, c, d, e; } eg[M]; int head[N], en; int dis[N], pre[N], rem[N]; bool inq[N]; int S, T, flow, cost; void SetEdge(int u, int v, int w, int z) { eg[++en] = (EG) {v, head[u], w, z, u}; head[u] = en; eg[++en] = (EG) {u, head[v], 0, -z, v}; head[v] = en; } void Clear() { memset(head, 0, sizeof head); en = 1; } bool Spfa() { memset(dis, 0x3f, sizeof dis); dis[S] = 0; memset(inq, 0, sizeof inq); inq[S] = 1; queue Q; Q.push(S); pre[S] = 0, rem[S] = INF; while (!Q.empty()) { int u = Q.front(); Q.pop(); inq[u] = 0; for (int e = head[u]; e; e = eg[e].b) { int v = eg[e].a; if (eg[e].c > 0 && dis[u] + eg[e].d < dis[v]) { dis[v] = dis[u] + eg[e].d; pre[v] = e; rem[v] = min(rem[u], eg[e].c); if (!inq[v]) { inq[v] = 1; Q.push(v); } } } } if (dis[T] == INF) return 0; flow += rem[T]; cost += dis[T] * rem[T]; int u = T; while (u != S) { eg[pre[u]].c -= rem[T]; eg[pre[u] ^ 1].c += rem[T]; u = eg[pre[u]].e; } return 1; } void MinCost() { flow = cost = 0; while (Spfa()); } int n, k, a[N], s[N], t[N], P, Q, m; void Main() { Clear(); scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); scanf("%d%d%d", &m, &P, &Q); for (int i = 1; i <= m; i++) scanf("%d%d", &s[i], &t[i]); S = 2 * n + 1; T = 2 * n + 2; SetEdge(S, 0, k, 0); int Flow = 0; for (int i = 1; i <= n; i++) { Flow += a[i]; SetEdge(S, i, a[i], 0); SetEdge(0, i + n, INF, 0); SetEdge(i + n, T, a[i], 0); if (i >= P) SetEdge(S, i + n, INF, Q); if (i + 1 <= n) SetEdge(i, i + 1, INF, 0); for (int j = 1; j <= m; j++) if (i + t[j] <= n) SetEdge(i, i + t[j] + n, INF, s[j]); } MinCost(); if (Flow - flow) puts("No solution"); else printf("%d\n", cost); } int main() { int T; scanf("%d", &T); while (T--) Main(); }