#include <bits/stdc++.h>
using namespace std;
const long long mod = (long long)1e9 + 7;
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<int> v(n);
  int sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  };
  int t;
  cin >> t;
  while (t--) {
    int b, c;
    cin >> b >> c;
    if (m[b] != 0) {
      int k = m[b];
      sum += (c - b) * k;
      m[b] = 0;
      m[c] += k;
    }
    cout << sum << endl;
  }
  return 0;
}
