#include <bits/stdc++.h>
const unsigned long long int mod = 1e9 + 7;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int n;
  cin >> n;
  vector<unsigned long long int> a(n);
  for (unsigned long long int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  unsigned long long int sum = 0;
  unsigned long long int q;
  cin >> q;
  for (unsigned long long int i = 0; i < q; ++i) {
    unsigned long long int b, c;
    cin >> b >> c;
    for (unsigned long long int j = 0; j < n; ++j) {
      if (a[j] == b) a[j] = c;
    }
    for (auto i : a) {
      sum += i;
    }
    cout << sum << "\n";
    sum = 0;
  }
}
