#include <bits/stdc++.h>
using namespace std;
ifstream fin("date.in");
int freq[100005];
int main() {
  int n, v[100005], q, x, y;
  unsigned long long sum = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> v[i];
    sum += v[i];
    freq[v[i]]++;
  }
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x >> y;
    int rem = freq[x];
    sum -= x * rem;
    freq[y] += rem;
    sum += y * rem;
    cout << sum << "\n";
  }
  return 0;
}
