#include <bits/stdc++.h>
using namespace std;
const long long P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
vector<int> vec(10001, 0);
int main() {
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  vector<int> A(N);
  long long sum = 0;
  for (int i = (0); i < (N); ++i) {
    cin >> A[i];
    sum += A[i];
    vec[A[i]]++;
  }
  int Q;
  cin >> Q;
  vector<int> B(Q), C(Q);
  for (int i = (0); i < (Q); ++i) cin >> B[i] >> C[i];
  for (int i = (0); i < (Q); ++i) {
    if (C[i] >= B[i]) {
      sum += vec[B[i]] * (C[i] - B[i]);
    } else {
      sum -= vec[B[i]] * (B[i] - C[i]);
    }
    if (B[i] != C[i]) {
      vec[C[i]] += vec[B[i]];
      vec[B[i]] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
