#include <bits/stdc++.h>
#include<cmath>
using namespace std;
typedef long long int l1;
typedef vector <int> vi;
typedef vector <long long int> v1;
#define pb push_back
#define iter(i,a,b) for(i=a;i<b;i++)
l1 sum(l1 a[], l1 n)
{
  l1 s=0,i;
  iter(i,0,n)
    s+=a[i];
  return s;
}
int main()
{
    ios_base::sync_with_stdio(false);      //for fast cin and cout streams
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    while(test--)
{
l1 n;
      cin>>n;
      l1 a[n],i;
      iter(i,0,n)
        cin>>a[i];
      l1 q;
      cin>>q;
      l1 b[q],c[q];
      iter(i,0,q)
        cin>>b[i]>>c[i];
      l1 o,l;
      iter(i,0,q)
      {
        o=b[i];
        l=c[i];
        replace(a,a+n,o,l)
          cout<<sum(a,n)<<"\n";
      }
      


    
   

}

return 0;
}




