#include <bits/stdc++.h>
const unsigned int M = 1000000007;
const long double PI = 3.141592653589793236L;
using namespace std;
void printString(long long int n) {
  long long int arr[10000];
  long long int i = 0;
  while (n) {
    arr[i] = n % 26;
    n = n / 26;
    i++;
  }
  for (long long int j = 0; j < i - 1; j++) {
    if (arr[j] <= 0) {
      arr[j] += 26;
      arr[j + 1] = arr[j + 1] - 1;
    }
  }
  for (long long int j = i; j >= 0; j--) {
    if (arr[j] > 0) cout << char('A' + arr[j] - 1 + 32);
  }
}
void solve() {
  int n;
  cin >> n;
  int a[n];
  map<int, int> values;
  map<int, int>::iterator it;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (values.find(a[i]) == values.end())
      values.insert(pair<int, int>(a[i], 1));
    else {
      it = values.find(a[i]);
      it->second++;
    }
    sum += a[i];
  }
  int q;
  cin >> q;
  int query[q][2];
  for (int i = 0; i < q; i++) {
    cin >> query[i][0] >> query[i][1];
  }
  for (int i = 0; i < q; i++) {
    int b = query[i][0];
    int c = query[i][1];
    it = values.find(b);
    if (it == values.end()) {
      cout << sum << endl;
      continue;
    }
    int subt = it->second;
    int tosubt = it->first;
    sum -= subt * tosubt;
    values.erase(it);
    it = values.find(c);
    if (it == values.end()) {
      values.insert(pair<int, int>(c, subt));
    } else {
      it->second += subt;
    }
    sum += c * subt;
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T = 1;
  solve();
  return 0;
}
