#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
char tolower(char c) { return (c + 0x20); }
char toupr(char c) { return (c - 0x20); }
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int ai;
    cin >> ai;
    sum += ai;
    ++m[ai];
  }
  int q;
  cin >> q;
  for (int _ = 0; _ < q; _++) {
    int b, c;
    cin >> b >> c;
    sum -= m[b] * b;
    sum += m[b] * c;
    cout << sum << endl;
    m[c] += m[b];
    m[b] = 0;
  }
}
