#include <bits/stdc++.h>
using namespace std;
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
constexpr double eps = 1e-9;
constexpr double pi = 3.141592653589793238462643383279;
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return (b);
  else
    return (gcd(b, a % b));
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow(long long x, long long n, long long m) {
  if (n == 0) return 1;
  if (n % 2 == 0)
    return pow(x * x % m, n / 2, m);
  else
    return x * pow(x, n - 1, m) % m;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  int q;
  cin >> q;
  vector<int> b(n);
  vector<int> c(n);
  for (long long i = 0; i < q; i++) cin >> b[i] >> c[i];
  sort(a.begin(), a.end());
  long long sum = 0;
  for (long long i = 0; i < n; i++) sum += a[i];
  vector<int> kosuu(100001, 0);
  for (long long i = 0; i < n; i++) kosuu[a[i]]++;
  for (long long i = 0; i < q; i++) {
    int sa = c[i] - b[i];
    sum += kosuu[b[i]] * sa;
    kosuu[c[i]] += kosuu[b[i]];
    kosuu[b[i]] = 0;
    cout << sum << endl;
  }
}
