int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n){
    cin >> a[i];
  }
  int q;
  cin >> q;
  ll fin=0;
  rep(i,q){
    int b,c;
    cin >> b >> c;
    ll ans=0;
    rep(j,n){
      if(a[j]==b){
        ans+=c;
      }
      else{
        ans+=b;
      }
    }
    cout << ans << endl;
  }
  return 0;
}