#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
void setIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
bool comp(pii a, pii b) {
  return a.first == b.first ? a.second < b.second : a.first < b.first;
}
int main() {
  setIO();
  int n;
  cin >> n;
  int a[n];
  ll sum = 0;
  int count[100001];
  fill(count, count + n, 0);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
    ++count[a[i]];
  }
  int q;
  cin >> q;
  while (q--) {
    int ai, bi;
    cin >> ai >> bi;
    sum += count[ai] * (bi - ai);
    count[bi] += count[ai];
    count[ai] = 0;
    cout << sum << "\n";
  }
}
