#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll power(ll x, ll y) {
  ll temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
void solve() {
  int n, q;
  cin >> n;
  vector<ll> a(n);
  for (auto &it : a) cin >> it;
  ;
  int arr[100005] = {0};
  for (int i = 0; i < n; i++) {
    arr[a[i]]++;
  }
  ll sum = 0;
  for (int i = 0; i < n; i++) {
    sum += a[i];
  }
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum = sum - b * arr[b] + c * arr[b];
    arr[c] += arr[b];
    arr[b] = 0;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
