#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;
int main() {
  int n;
  cin >> n;
  vector<int> x(100001, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    x.at(a)++;
  }
  int sum = 0;
  for (int i = 1; i <= n; i++) {
    sum += (i * x.at(i));
  }
  int q;
  cin >> q;
  vector<int> ans;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    x.at(c) += x.at(b);
    sum += (c - b) * x.at(b);
    x.at(b) = 0;
    ans.push_back(sum);
  }
  for (int i = 0; i < ans.size(); i++) cout << ans.at(i) << endl;
}
