#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> as;
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (as.find(a) == as.end()) {
      as.insert(make_pair(a, 1));
    } else {
      ++as[a];
    }
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    int bc;
    if (as.find(b) == as.end()) {
      bc = 0;
    } else {
      bc = as[b];
      as[b] = 0;
    }
    if (as.find(c) == as.end()) {
      as.insert(make_pair(c, bc));
    } else {
      as[c] += bc;
    }
    sum += (c - b) * bc;
    cout << sum << endl;
  }
  return 0;
}
