#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 100005;
int freq[N], v[N];
void solve() {
  int n, q;
  long long int sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    freq[v[i]]++;
    sum += v[i];
  }
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= (freq[x] * x);
    sum += (freq[x] * y);
    freq[y] += freq[x], freq[x] = 0;
    cout << sum << '\n';
  }
}
int main() {
  cin.tie(NULL), cout.sync_with_stdio(true);
  int t = 1;
  while (t--) solve();
  return 0;
}
