#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
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() {
  long long sum = 0;
  int t[10010];
  for (int i = 0; i <= 10001; ++i) t[i] = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int temp;
    cin >> temp;
    ++t[temp];
    sum += temp;
  }
  int q;
  cin >> q;
  vector<long long> ans(q);
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    sum = sum + (c - b) * t[b];
    ans[i] = sum;
    t[c] += t[b];
    t[b] = 0;
  }
  for (int i = 0; i < q; ++i) printf("%lld \n", ans[i]);
}
