#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
int x,y,c,d,next,other;
}a[2100000];int len,last[2100000];
const int INF=99999999;
void ins(int x,int y,int c,int d)
{
int k1,k2;
k1=++len;
a[len].x=x;a[len].y=y;a[len].c=c;a[len].d=d;
a[len].next=last[x];last[x]=len;
k2=++len;
a[len].x=y;a[len].y=x;a[len].c=0;a[len].d=-d;
a[len].next=last[y];last[y]=len;
a[k1].other=k2;
a[k2].other=k1;
}
int st,ed;
int head,tail,list[21000];
int pre[21000],cc[21000],d[21000];
bool v[21000];
int ans,flow;
bool spfa()
{
for(int i=1;i<=ed;i++)d[i]=999999999;
d[st]=0;
memset(cc,0,sizeof(cc));cc[st]=9999999;
memset(v,false,sizeof(v));v[st]=true;
list[1]=st;head=1;tail=2;
while(head<=tail)
{
int x=list[head];
for(int k=last[x];k;k=a[k].next)
{
int y=a[k].y;
if(d[y]>d[x]+a[k].d&&a[k].c>0)
{
d[y]=d[x]+a[k].d;
cc[y]=min(cc[x],a[k].c);
pre[y]=k;
if(v[y]==false)
{
v[y]=true;
list[tail++]=y;
if(tail==20000)tail=1;
}
}
}
v[x]=false;
head++;if(head==20000)head=1;
}
if(d[ed]==999999999)return false;
ans+=cc[ed]*d[ed];flow+=cc[ed];
int x=ed;
while(x!=0)
{
int k=pre[x];
a[k].c-=cc[ed],a[a[k].other].c+=cc[ed];
x=a[k].x;
}
return true;
}
int main()
{
int T;
scanf("%d",&T);
for(int ti=1;ti<=T;ti++)
{
int n,m,k;
len=0;memset(last,0,sizeof(last));
scanf("%d%d%d",&n,&m,&k);
st=0,ed=2*n+m+1;
int sum=0;flow=ans=0;
for(int i=1;i<=n;i++)
{
int x;
scanf("%d",&x);sum+=x;
ins(st,i,x,0);ins(i+n,ed,x,0);
if(i!=n)ins(i,i+1,INF,0);
}
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%d%d",&x,&y);
ins(st,i+2*n,x,0);
for(int j=1;j<=n;j++)ins(i+2*n,j+n,x,y);
}
for(int i=1;i<=k;i++)
{
int x,y;
scanf("%d%d",&x,&y);
for(int j=1;j<=n;j++)
if(j+x+1<=n)
ins(j,j+x+1+n,INF,y);
}
while(spfa()==true){}
printf("Case %d: ",ti);
if(flow==sum)printf("%d\n",ans);
else printf("impossible\n");
}
return 0;
}