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