#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long temp;
  while (b > 0) {
    temp = a % b;
    a = b;
    b = temp;
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long fpow(long long b, long long exp, long long mod) {
  if (exp == 0) return 1;
  long long t = fpow(b, exp / 2, mod);
  if (exp & 1) return t * t % mod * b % mod;
  return t * t % mod;
}
long long divmod(long long i, long long j, long long mod) {
  i %= mod, j %= mod;
  return i * fpow(j, mod - 2, mod) % mod;
}
clock_t time_p = clock();
void TimeTaken() {
  time_p = clock() - time_p;
  cerr << "Completion time : " << (float)(time_p) / CLOCKS_PER_SEC << "\n";
}
void solve() {}
int main() {
  int a[100001] = {0};
  int n, q, b, c, s = 0;
  cin >> n;
  vector<long long> v(n);
  for (int i = int(0); i <= int(n - 1); i++) {
    cin >> v[i];
    s += v[i];
    a[v[i]]++;
  }
  cin >> q;
  for (int i = int(1); i <= int(q); i++) {
    cin >> b >> c;
    s = s + ((c - b) * a[b]);
    a[c] = a[c] + a[b];
    a[b] = 0;
    cout << s << "\n";
  }
  return 0;
}
