#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, Q;
  cin >> N;
  long long sum, M;
  vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sum = accumulate(A.begin(), A.end(), 0);
  long long B, C;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    M = count(A.begin(), A.end(), B);
    replace(A.begin(), A.end(), B, C);
    sum = sum + M * (C - B);
    cout << sum << endl;
  }
  return 0;
}
