#include <bits/stdc++.h>

using namespace std;

int main(void){
  int N = 0;
  cin >> N;
  
  int A[N] = {0};
  
  for(int i=0;i<N;i++){
    cin >> A[i]; 
  }
  
  int Q = 0;
  cin >> Q;
  
  for(int i=0;i<Q;i++){
    int B=0;
    int C=0;
    int sum=0;
    cin >> B;
    cin >> C;
    for(int j=0;j<N;j++){
      if(A[j]==B){
        A[j] = C;
      }
      sum += A[i];
    }
  	cout << sum << endl;
  }
  
  return 0;
}
