#include <bits/stdc++.h>
using namespace std;
vector<int> factors(int x) {
  vector<int> result;
  int i = 1;
  while (i * i <= x) {
    if (x % i == 0) {
      result.push_back(i);
      if (x / i != i) {
        result.push_back(x / i);
      }
    }
    i++;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  int a[n];
  int it;
  long long s = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> it;
    s += it;
    m[it]++;
    a[i] = it;
  }
  long long q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    s -= (b * m[b]);
    s += (c * m[b]);
    m[c] += m[b];
    m[b] = 0;
    cout << s << endl;
  }
  return 0;
}
