#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> numCnt(100001);
  long long sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    int a;
    cin >> a;
    numCnt[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  vector<long long> ans(q + 1);
  ans[0] = sum;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    ans[i + 1] = ans[i] - numCnt[b] * b + numCnt[b] * c;
    numCnt[c] += numCnt[b];
    numCnt[b] = 0;
  }
  for (int i = 0; i < (int)(q); i++) cout << ans[i + 1] << endl;
  return 0;
}
