#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x3fffffff
#define pa pair<int,int>
#define pi 3.1415926535897932384626433832795028841971
#define S 0
#define T 1001
#define N 1010
using namespace std;
inline LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}
while(ch>=‘0‘&&ch<=‘9‘){x=x*10+ch-‘0‘;ch=getchar();}
return x*f;
}
struct edge{int to,next,v,from,c;}e[100*N];
int head[N],dist[N],q[N],from[N];
bool mrk[N];
int n,m,k,cnt,ans;
inline void ins(int u,int v,int w,int c)
{
e[++cnt].to=v;
e[cnt].v=w;
e[cnt].c=c;
e[cnt].from=u;
e[cnt].next=head[u];
head[u]=cnt;
}
inline void insert(int u,int v,int w,int c)
{
ins(u,v,w,c);
ins(v,u,0,-c);
}
inline bool spfa()
{
for(int i=0;i<=T;i++)dist[i]=inf;
int t=0,w=1;
dist[S]=0;q[0]=S;mrk[S]=1;
while (t!=w)
{
int now=q[t++];if (t==1005)t=0;
for (int i=head[now];i;i=e[i].next)
if (e[i].v&&dist[now]+e[i].c<dist[e[i].to])
{
dist[e[i].to]=dist[now]+e[i].c;
from[e[i].to]=i;
if (!mrk[e[i].to])
{
mrk[e[i].to]=1;
q[w++]=e[i].to;
if (w==1005)w=0;
}
}
mrk[now]=0;
}
return dist[T]!=inf;
}
inline void mcf()
{
int x=inf;
for (int i=from[T];i;i=from[e[i].from])
x=min(x,e[i].v);
for (int i=from[T];i;i=from[e[i].from])
{
e[i].v-=x;
e[i^1].v+=x;
ans+=x*e[i].c;
}
}
inline void work(int dfn)
{
memset(head,0,sizeof(head));
cnt=1;ans=0;
n=read();m=read();k=read();
for (int i=1;i<=n;i++)
{
int x=read();
insert(S,i,x,0);
insert(i+n,T,x,0);
if (i!=n)insert(i+n,i+n+1,inf,0);
}
for (int i=1;i<=m;i++)
{
int x=read(),y=read();
insert(0,n+1,x,y);
}
for (int i=1;i<=k;i++)
{
int x=read(),y=read();
for (int j=1;j<=n;j++)
if (j+x+1<=n)insert(j,j+x+1+n,inf,y);
}
printf("Case %d: ",dfn);
while (spfa())mcf();
bool mrk=0;
for(int i=2;i<=cnt;i+=2)
if (e[i].to==T&&e[i].v)
{
printf("impossible\n");
return;
}
printf("%d\n",ans);
}
int main()
{
int tt=read();
for(int i=1;i<=tt;i++)work(i);
}