#include <bits/stdc++.h>
using namespace std;
void solve(vector<int>& v, int a, int b) {
  int n = v.size();
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (v[i] == a) v[i] = b;
    sum += v[i];
  }
  cout << sum << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  vector<int> v;
  int n;
  while (t--) {
    cin >> n;
    v.push_back(n);
  }
  int m;
  cin >> m;
  int a, b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    solve(v, a, b);
  }
  return 0;
}
