#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, q, max = 0, buf, buf_1, buf_2;
  cin >> n;
  vector<long long int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> buf;
    v.at(i) = buf;
    if (buf > max) max = buf;
  }
  cin >> q;
  vector<pair<long long int, long long int>> p(q);
  for (int i = 0; i < q; i++) {
    cin >> buf_1 >> buf_2;
    p.at(i).first = buf_1;
    p.at(i).second = buf_2;
    if (buf_2 > max) max = buf_2;
  }
  vector<long long int> vv(100000, 0), l;
  for (long long int num : v) {
    vv.at(num - 1)++;
  }
  long long int sum = accumulate(v.begin(), v.end(), 0);
  for (auto p_buf : p) {
    buf_1 = p_buf.first;
    buf_2 = p_buf.second;
    sum += vv.at(buf_1 - 1) * (buf_2 - buf_1);
    vv.at(buf_2 - 1) += vv.at(buf_1 - 1);
    vv.at(buf_1 - 1) = 0;
    l.push_back(sum);
  }
  for (auto n : l) {
    cout << n << endl;
  }
  return 0;
}
