#include <bits/stdc++.h>
using namespace std;
vector<string> split(const string &s, char delim) {
  vector<string> elems;
  string item;
  for (char ch : s) {
    if (ch == delim) {
      if (!item.empty()) {
        elems.push_back(item);
      }
      item.clear();
    } else {
      item += ch;
    }
  }
  if (!item.empty()) {
    elems.push_back(item);
  }
  return elems;
}
string to_str_with_zero(int i, int w) {
  ostringstream sout;
  sout << std::setfill('0') << std::setw(w) << i;
  string s = sout.str();
  return s;
}
int letter_to_int(char c) { return tolower(c) - 'a'; }
bool array_equal(vector<int> a1, vector<int> a2) {
  if (a1.size() != a2.size()) {
    return false;
  }
  for (int i = 0; i < a1.size(); i++) {
    if (a1.at(i) != a2.at(i)) {
      return false;
    }
  }
  return true;
}
int gcd(int a, int b) {
  if (a == b) {
    return a;
  } else if (a > b) {
    return gcd(a - b, b);
  } else {
    return gcd(a, b - a);
  }
}
int main() {
  std::cout << std::setprecision(9);
  int n;
  cin >> n;
  vector<int> a_count(100000);
  long sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    a_count.at(a)++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum += a_count.at(b) * (c - b);
    a_count.at(c) += a_count.at(b);
    a_count.at(b) = 0;
    cout << sum << endl;
  }
}
