#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  int a1[100005] = {0};
  vector<int> v1;
  int a;
  long long sum = 0;
  map<int, int> m1;
  for (int i = 0; i < n; ++i) {
    cin >> a;
    v1.push_back(a);
    a1[a] = 1;
    m1[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  int x, y;
  while (q--) {
    cin >> x >> y;
    if (a1[x] == 1) {
      int k = m1[x];
      m1[x] = 0;
      m1[y] = k + m1[y];
      sum += (y - x) * k;
    }
    cout << sum << endl;
  }
  return 0;
}
