#include <bits/stdc++.h>
using namespace std;
priority_queue<long long, vector<long long>, greater<long long> > que;
priority_queue<long long> Que;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int n;
int a[100005];
long long sum = 0;
void calc(int b, int c) {
  int x = a[b];
  sum -= (b * x);
  a[b] = 0;
  a[c] += x;
  sum += (c * x);
}
void solve() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
  }
  for (long long i = 1; i < 100005; i++) {
    sum += (i * a[i]);
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    calc(b, c);
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
