#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
using Graph = vector<vector<int>>;
using ipair = pair<long long int, long long int>;
bool operator<(const ipair a, const ipair b) { return a.first < b.first; };
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int lcm(long long int a, long long int b) {
  return a / gcd(a, b) * b;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n), cnt(100003, 0);
  for (long long int i = 0; i < (n); ++i) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  int q;
  cin >> q;
  vector<int> b(q), c(q);
  for (long long int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
  }
  long long int sum = 0;
  for (long long int i = 0; i < (n); ++i) sum += a[i];
  for (long long int i = 0; i < (q); ++i) {
    sum -= b[i] * cnt[b[i]];
    sum += c[i] * cnt[b[i]];
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
