#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  unordered_map<int, int> data;
  long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    data[a[i]] = 0;
    sum += a[i];
  }
  for (int i = 0; i < n; i++) {
    data[a[i]] = data[a[i]] + 1;
  }
  int q;
  cin >> q;
  vector<int> num;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int v = c - b;
    sum = sum + v * data[b];
    if (data.count(c)) {
      data[c] = data[c] + data[b];
    } else {
      data[c] = data[b];
    }
    data.erase(b);
    num.push_back(sum);
  }
  for (auto i : num) {
    cout << i << endl;
  }
}
