#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  long long int res = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    res += a[i];
    m[a[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b;
    cin >> c;
    long long int temp = res;
    if (m[b] != 0) {
      temp = temp - (m[b] * b);
      temp = temp + (c * m[b]);
      m[c] += m[b];
      m[b] = 0;
      res = temp;
    }
    cout << temp << endl;
  }
}
