#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  int q;
  int x;
  vector<int> v;
  long long int s = 0;
  map<int, int> freq;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    v.push_back(x);
    freq[x]++;
    s += x;
  }
  cin >> q;
  int a, b;
  for (int i = 0; i < q; ++i) {
    cin >> a >> b;
    s -= a * freq[a];
    s += b * freq[a];
    freq[b] += freq[a];
    freq[a] = 0;
    cout << s << "\n";
  }
  return 0;
}
