1 #include<cstdio>
2 #include<iostream>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #define maxn 105
7 #define maxm 20300
8 #define inf 1061109567
9 using namespace std;
10 char ch;
11 bool ok;
12 void read(int &x){
13 ok=0;
14 for (ch=getchar();!isdigit(ch);ch=getchar()) if (ch==‘-‘) ok=1;
15 for (x=0;isdigit(ch);x=x*10+ch-‘0‘,ch=getchar());
16 if (ok) x=-x;
17 }
18 int T,n,m,k,x,y,sum;
19 struct costflow{
20 int s,t,tot,now[maxn],son[maxm],pre[maxm],val[maxm],cost[maxm];
21 int dis[maxn],tmp,totflow,totcost,sla[maxn],head,tail,list[maxn],path[maxn];
22 bool bo[maxn];
23 void init(){s=0,t=(n<<1)+1,tot=1,memset(now,0,sizeof(now));}
24 void put(int a,int b,int c,int d){pre[++tot]=now[a],now[a]=tot,son[tot]=b,val[tot]=c,cost[tot]=d;}
25 void add(int a,int b,int c,int d){put(a,b,c,d),put(b,a,0,-d);}
26 int dfs(int u,int rest,int totval){
27 if (u==t){totcost+=rest*totval;return rest;}
28 int ans=0; bo[u]=1;
29 for (int p=now[u],v=son[p];p&&rest;p=pre[p],v=son[p])
30 if (val[p]&&!bo[v]){
31 int t=dis[u]+cost[p]-dis[v];
32 if (!t){
33 int d=dfs(v,min(rest,val[p]),totval+cost[p]);
34 val[p]-=d,val[p^1]+=d,ans+=d,rest-=d;
35 }
36 else sla[v]=min(sla[v],t);
37 }
38 return ans;
39 }
40 bool relax(){
41 int d=inf;
42 for (int u=s;u<=t;u++) if (!bo[u]) d=min(d,sla[u]);
43 if (d==inf) return false;
44 for (int u=s;u<=t;u++) if (!bo[u]) dis[u]+=d;
45 return true;
46 }
47 void work(){
48 memset(dis,0,sizeof(dis)),totflow=totcost=0;
49 do{
50 memset(sla,63,sizeof(sla));
51 do{
52 memset(bo,0,sizeof(bo));
53 tmp=dfs(s,inf,0),totflow+=tmp;
54 }while (tmp);
55 }while (relax());
56 }
57 }f;
58 int main(){
59 int Case=0;
60 for (read(T);T;T--){
61 read(n),read(m),read(k),f.init(),sum=0,Case++;
62 for (int i=1;i<=n;i++) read(x),sum+=x,f.add(i,f.t,x,0),f.add(f.s,i+n,x,0);
63 for (int i=1;i<n;i++) f.add(i,i+1,inf,0);
64 for (int i=1;i<=m;i++) read(x),read(y),f.add(f.s,1,x,y);
65 for (int i=1;i<=k;i++){
66 read(x),read(y);
67 for (int j=1;j<=n-x-1;j++) f.add(j+n,j+x+1,inf,y);
68 }
69 f.work();
70 printf("Case %d: ",Case);
71 if (f.totflow==sum) printf("%d\n",f.totcost);
72 else puts("impossible");
73 }
74 return 0;
75 }