using namespace std;
int main()
{
  long long int n,t,i;
  cin>>n;int arr[n];
  for(i=0;i<n;i++)
    cin>>arr[i];
  cin>>t;
  while(t--)
  {
    int search,replace,sum=0;
    cin>>search>>replace;
    for(i=0;i<n;i++)
    {
      if(arr[i]==search)
      arr[i]=replace;
    }
    for(i=0;i<n;i++)
    sum+=arr[i];
    cout<<sum<<endl;
  }
}