#include <bits/stdc++.h>
using namespace std;
const long long INFL = 1e18;
const int INF = 1001001001;
const int mod = 1000000007;
const double PI = acos(-1);
template <typename TypeInt>
std::string Itoa(const TypeInt v, int base) {
  static const char table[] = "zabcdefghijklmnopqrstuvwxyz";
  string ret;
  static numeric_limits<TypeInt> t;
  TypeInt n = v;
  if (t.is_signed) {
    if (v < 0) n *= -1;
  }
  while (n >= base) {
    ret += table[n % base];
    n /= base;
  }
  ret += table[n];
  if (t.is_signed) {
    if (v < 0 && base == 10) ret += '-';
  }
  std::reverse(ret.begin(), ret.end());
  return ret;
}
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    m[a]++;
  }
  long long sum = 0;
  for (auto x : m) {
    sum += x.first * x.second;
  }
  int q;
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int b, c;
    cin >> b >> c;
    int cnt = m[b];
    m[b] = 0;
    sum -= b * cnt;
    sum += c * cnt;
    m[c] += cnt;
    cout << sum << endl;
  }
}
