#include<iostream>
using namespace std;
int main()
{
  int N;
  cin>>N;
  int arr[N];
  for(int i=0;i<N;i++)
    cin>>arr[i];
  int Q;
  cin>>Q;
  int B[Q],C[Q]
  for(int i=0;i<Q;i++)
  {
    cin>>B[i];
    cin>>C[i];
  }
  int i = 0;
  while(i<Q)
  {
    for(int j=0;j<N;j++)
    {
      if(arr[j] == B[i])
        arr[j] = C[i];
    }
    int sum = 0;
    for(int j=0;j<N;j++)
    {
      sum = sum + arr[j];
      cout<<sum<<" ";
    }
    cout<<"\n";
    i++;
  }
}
