#include #include #include #include #define MAX 100000 using namespace std; struct edge { int x,next,value; }e[20*MAX]; int cnt,head[MAX],c[MAX],a[MAX],d[MAX]; bool visited[MAX],flag[MAX]; void add(int u,int v,int w) { e[cnt].x=v; e[cnt].value=w; e[cnt].next=head[u]; head[u]=cnt++; } bool SPFA(int s,int n) { int tnext,tx,temp; memset(visited,false,sizeof(visited)); memset(c,0,sizeof(c)); queueQ; while(!Q.empty()) Q.pop(); Q.push(s); c[s]++; d[s]=0; visited[s]=true; flag[s]=true; while(!Q.empty()) { temp=Q.front();Q.pop(); tnext=head[temp]; while(tnext!=-1) { tx=e[tnext].x; if(d[tx]n) return false; visited[tx]=true; } } tnext=e[tnext].next; } visited[temp]=false; } return true; } int main() { int n,i,u,v,k=1; string str; while(cin>>n&&n) { cnt=0; for(i=1;i<=n;i++)cin>>a[i]; for(i=0;i>str&&str!="#") { cin>>u>>v; if(str=="SAS") add(v,u,0); if(str=="SAF") add(v,u,a[v]); if(str=="FAF") add(v,u,a[v]-a[u]); if(str=="FAS") add(v,u,-a[u]); } cout<<"Case "<