#include <bits/stdc++.h>
using namespace std;
int main() {
  int nums[100001];
  int N, Q, b, B, C;
  long long sum;
  vector<long long> res;
  for (int i = 0; i < 100001; i++) nums[i] = 0;
  cin >> N;
  sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> b;
    nums[b]++;
    sum += b;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    sum = sum - B * nums[B] + C * nums[B];
    res.push_back(sum);
    nums[C] += nums[B];
    nums[B] = 0;
  }
  for (int i = 0; i < Q; i++) cout << res[i] << "\n";
  return 0;
}
