#include <bits/stdc++.h>
using namespace std;
size_t array_count_values(vector<int> array, size_t size, int value) {
  size_t count = 0;
  for (size_t i = 0; i < size; ++i) {
    if (array[i] == value) {
      ++count;
    }
  }
  return count;
}
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cin >> q;
  vector<int> b(q), c(q);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  vector<long long> s(q + 1);
  vector<int> count(100001);
  for (int i = 1; i <= 100000; i++) {
    count[i] = array_count_values(a, n, i);
  }
  for (int i = 0; i < n; i++) {
    s[0] += a[i];
  }
  for (int i = 0; i < q; i++) {
    s[i + 1] = s[i] + (c[i] - b[i]) * count[b[i]];
    count[c[i]] += count[b[i]];
    count[b[i]] = 0;
  }
  for (int i = 1; i <= q; i++) {
    cout << s[i] << endl;
  }
}
