#include <bits/stdc++.h>
using namespace std;
vector<int> remove_duplicate_elements(vector<int> v) {
  vector<int>::iterator ip;
  ip = unique(v.begin(), v.end());
  v.resize(std::distance(v.begin(), ip));
  return v;
}
string make_unique_string(string s) {
  string s1 = "";
  for (int i = 0; i < s.length(); i++) {
    bool flag = true;
    for (int j = 0; j < s1.length(); j++) {
      if (s1[j] == s[i]) {
        flag = false;
        break;
      }
    }
    if (flag) s1 = s1 + s[i];
  }
  return s1;
}
struct vec_thre {
  int first, second, third;
};
bool comp(vec_thre a, vec_thre b) {
  if (a.first != b.first) return a.first < b.first;
  if (a.second != b.second) return a.second < b.second;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first != b.first) return (a.first > b.first);
  return (a.second > b.second);
}
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (long long i = 0, temp; i < n; i++) {
    cin >> temp;
    v.push_back(temp);
  };
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (v[i] == a) v[i] = b;
    }
    cout << accumulate(v.begin(), v.end(), 0) << "\n";
  }
  return 0;
}
