#include <bits/stdc++.h>
using namespace std;
const double epsilon = 1e-7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  unordered_map<int, int> m;
  int x;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (m.find(x) == m.end()) m[x] = 0;
    m[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    int count = m[b];
    m.erase(b);
    sum -= b * count;
    if (m.find(c) != m.end())
      m[c] += count;
    else
      m[c] = count;
    sum += c * count;
    cout << sum << endl;
  }
  return 0;
}
