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