#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < (signed)(n); ++i) cin >> a[i];
  map<int, int> m;
  long long total_sum = 0;
  for (int i = 0; i < (signed)(n); ++i) {
    ++m[a[i]];
    total_sum += a[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < (signed)(q); ++i) {
    int b, c;
    cin >> b >> c;
    int count = m[b];
    total_sum -= count * b;
    total_sum += count * c;
    m.erase(b);
    m[c] += count;
    cout << total_sum << '\n';
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
