#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
const double E = 1e-9;
int count(int arr[], int x, int n) {
  int *low = lower_bound(arr, arr + n, x);
  if (low == (arr + n) || *low != x) return 0;
  int *high = upper_bound(low, arr + n, x);
  return high - low;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, sum = 0;
  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    ++mp[a[i]];
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum += (y - x) * mp[x];
    cout << sum << "\n";
    replace(a, a + n, x, y);
    mp[y] += mp[x];
    mp[x] = 0;
  }
  return 0;
}
