#include <bits/stdc++.h>
using namespace std;
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
const long long INF = numeric_limits<long long>::max();
int main() {
  int N;
  cin >> N;
  vector<int> A;
  long long ans = 0;
  for (int i = 0; i < (N); i++) {
    int tmp;
    cin >> tmp;
    A.push_back(tmp);
    ans += tmp;
  }
  int Q;
  cin >> Q;
  vector<int> B, C;
  for (int i = 0; i < (Q); i++) {
    int b, c;
    cin >> b >> c;
    B.push_back(b);
    C.push_back(c);
  }
  map<int, int> nums;
  for (int i = 0; i < (N); i++) {
    if (nums.count(A[i])) {
      nums[A[i]]++;
    } else {
      nums[A[i]] = 1;
    }
  }
  for (int i = 0; i < (Q); i++) {
    if (!nums.count(B[i])) {
      cout << ans << endl;
      continue;
    }
    if (B[i] > C[i]) {
      ans = ans - (nums[B[i]] * B[i]) + nums[B[i]] * C[i];
      cout << ans << endl;
      if (nums.count(C[i])) {
        nums[C[i]] += nums[B[i]];
      } else {
        nums[C[i]] = nums[B[i]];
      }
      nums[B[i]] = 0;
    } else {
      ans = ans - (nums[B[i]] * B[i]) + nums[B[i]] * C[i];
      cout << ans << endl;
      if (nums.count(C[i])) {
        nums[C[i]] += nums[B[i]];
      } else {
        nums[C[i]] = nums[B[i]];
      }
      nums[B[i]] = 0;
    }
  }
  return 0;
}
