#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, a[100010] = {0}, b[100010] = {0}, c[100010] = {0},
                  s[100010] = {0}, cnt[100010] = {0};
  cin >> N;
  for (long long i = 0; i < (N); i++) {
    cin >> a[i];
    cnt[a[i] - 1]++;
  }
  cin >> Q;
  for (long long i = 0; i < (Q); i++) {
    cin >> b[i] >> c[i];
  }
  for (long long i = 0; i < (N); i++) {
    s[0] += a[i];
  }
  for (long long i = 0; i < (Q); i++) {
    s[i + 1] = s[i] + (c[i] - b[i]) * cnt[b[i] - 1];
    cnt[c[i] - 1] += cnt[b[i] - 1];
  }
  for (int i = 1; i <= Q; i++) {
    cout << (s[i]) << endl;
  }
}
