#include <bits/stdc++.h>
using namespace std;
template <typename T>
std::vector<T> slice(std::vector<T> const &v, int m, int n) {
  auto first = v.cbegin() + m;
  auto last = v.cbegin() + n + 1;
  std::vector<T> vec(first, last);
  return vec;
}
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
T get() {
  T s;
  cin >> s;
  return (s);
}
template <class T>
vector<T> getv(int n) {
  vector<T> v(n);
  for (long long i = 0; i < (long long)(n); i++) cin >> v[i];
  return v;
}
void print(int a) { cout << a << endl; }
void print(long long a) { cout << std::fixed << a << endl; }
void print(string a) { cout << a << endl; }
void print(char a) { cout << a << endl; }
void print(double a) { cout << a << endl; }
void print(double a, int dig) { cout << std::setprecision(dig) << a << endl; }
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v) {
  o << "{";
  for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
  o << "}";
  return o;
}
template <class T = int>
void print(vector<T> v) {
  cout << v << endl;
}
template <class T = int>
void print2dVec(vector<vector<T>> v2d) {
  for (vector<T> v : v2d) {
    print(v);
  }
}
void YesNo1(bool i = true) { return print(i ? "Yes" : "No"); }
void YESNO2(bool i = true) { return print(i ? "YES" : "NO"); }
template <class T>
void debug(T &var, int nest = 0, string before = "") {
  cout << string("          ", nest) << before;
  print(var);
}
const long long INF = 1e18;
const int MOD = 1000000007;
const vector<string> alphabets = {"a", "b", "c", "d", "e", "f", "g", "h", "i",
                                  "j", "k", "l", "m", "n", "o", "p", "q", "r",
                                  "s", "t", "u", "v", "w", "x", "y", "z"};
int factorial(int k) {
  int sum = 1;
  for (int i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
  long long temp = gcd(a, b);
  return temp ? (a / temp * b) : 0;
}
vector<pair<long long, long long>> prime_factorize(long long N) {
  vector<pair<long long, long long>> res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}
string capitalize(string s) {
  string newS = "";
  for (char c : s) {
    newS += toupper(c);
  }
  return newS;
}
void Main() {
  int n = get<int>();
  vector<int> nums = getv<int>(n);
  map<int, int> count;
  int sum = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    count[nums[i]]++;
    sum += nums[i];
  }
  int q = get<int>();
  for (long long i = 0; i < (long long)(q); i++) {
    int b = get<int>(), c = get<int>();
    sum += count[b] * (c - b);
    print(sum);
    count[c] += count[b];
    count[b] = 0;
  }
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  Main();
}
