#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long n, sum = 0;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
    a[v[i]]++;
  }
  sort((v).begin(), (v).end());
  int k;
  cin >> k;
  int lsum = sum;
  while (k--) {
    int x, y;
    cin >> x >> y;
    lsum = lsum - x * a[x];
    lsum = lsum + y * a[x];
    cout << lsum << '\n';
    a[y] += a[x];
    a[x] = 0;
  }
}
