#include <bits/stdc++.h>
using namespace std;
template <typename T>
void max_self(T& a, T b) {
  a = max(a, b);
}
template <typename T>
void min_self(T& a, T b) {
  a = min(a, b);
}
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  int sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  int q;
  cin >> q;
  vector<int> ans(q);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int qtd = m[a];
    sum -= a * qtd;
    sum += b * qtd;
    m[a] = 0;
    m[b] += qtd;
    ans[i] = sum;
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
