#include <bits/stdc++.h>
using namespace std;
void Sum(int data[], int N) {
  long long sum = 0;
  for (int i = 0; i < N; i++) sum += data[i];
  cout << sum << endl;
}
void My_Replace(int data[], int B, int C, int N) {
  for (int i = 0; i < N; i++) {
    if (data[i] == B) data[i] = C;
  }
}
int main() {
  int N, Q, B, C;
  cin >> N;
  int data[N];
  for (int i = 0; i < N; i++) cin >> data[i];
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    My_Replace(data, B, C, N);
    Sum(data, N);
  }
}
