#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, x, y, q;
  cin >> n;
  vector<long long int> a, b, c;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    a.push_back(x);
  }
  cin >> q;
  for (long long int i = 0; i < q; i++) {
    cin >> x >> y;
    b.push_back(x);
    c.push_back(y);
  }
  long long int sum = 0;
  for (long long int i = 0; i < q; i++) {
    for (long long int j = 0; j < n; j++) {
      if (b[i] == a[j]) a[j] = c[i];
      sum = sum + a[j];
    }
    cout << sum << "\n";
    sum = 0;
  }
  return 0;
}
