#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < (n); ++i) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < (q); ++i) cin >> b[i] >> c[i];
  vector<int> x(100005);
  int sum = 0;
  for (int i = 0; i < (n); ++i) {
    x[a[i]]++;
    sum += a[i];
  }
  for (int i = 0; i < q; i++) {
    int count = x[b[i]];
    int dif = (c[i] - b[i]) * count;
    x[b[i]] = 0;
    x[c[i]] += count;
    sum += dif;
    cout << sum << endl;
  }
}
