#include <bits/stdc++.h>
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> num;
  int sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    num[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    int numb = num[b];
    if (numb > 0) {
      sum -= numb * b;
      sum += numb * c;
      num[c] += numb;
      num[b] = 0;
    }
    cout << sum << endl;
  }
  return 0;
}
