#include <bits/stdc++.h>
using namespace std;
void solve(int cnum) {
  int64_t n;
  cin >> n;
  vector<int64_t> arr(n);
  vector<int64_t> freq(n);
  int64_t sum = 0;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    sum += arr[i];
    freq[arr[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int64_t a, b;
    cin >> a >> b;
    int64_t num = freq[a];
    int64_t torem = a * num;
    freq[a] = 0;
    sum -= torem;
    torem = b * num;
    sum += torem;
    freq[b] += num;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int t;
  int count = 1;
  for (t = 1; t--; solve(count))
    ;
  return 0;
}
