#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<string>
using namespace std;
int a[100005],c[100000],v[100005];
int n,i,j,sum,vist,m;
int main()
{
long long int ans;
ios::sync_with_stdio(false);
cin>>n;
for(i=1;i<=n;i++)cin>>a[i];
cin>>m;
for(i=1;i<=m;i++)
{
cin>>c[i];
v[c[i]]=1;
sum=(sum+a[c[i]])%9999997;
}
for(i=1;i<=n;i++)
{
if (v[i]==0) ans=(ans+ans*a[i]+a[i])%9999997;
long long vist=ans;
for (int i=1;i<=m;i++)
ans=(ans+vist*a[c[i]])%9999997;
ans=(ans+sum)%9999997;
cout<<ans;
}
}