#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int a[10005] = {};
  long long int n;
  cin >> n;
  long long int temp;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    a[temp]++;
    ans += temp;
  }
  long long int q;
  cin >> q;
  vector<long long int> b;
  vector<long long int> c;
  for (int i = 0; i < q; i++) {
    cin >> temp;
    b.push_back(temp);
    cin >> temp;
    c.push_back(temp);
  }
  for (int i = 0; i < q; i++) {
    ans += a[b[i]] * (c[i] - b[i]);
    cout << ans;
    if (i != q - 1) cout << "\n";
    a[c[i]] += a[b[i]];
    a[b[i]] = 0;
  }
  return 0;
}
