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