#include <bits/stdc++.h>
using namespace std;
const unsigned int m = 1000000007;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> m;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int ele;
    cin >> ele;
    m[ele]++;
    sum += ele;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int count = m[a];
    m[a] = 0;
    m[b] += count;
    int new_sum = sum + (b - a) * count;
    cout << new_sum << endl;
    sum = new_sum;
  }
}
