#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long int inf = 1e18;
const long long int ninf = -1e18;
const long long int mod = 1000000007;
const long long int MOD = 998244353;
template <typename T>
bool asc(pair<T, T> &a, pair<T, T> &b) {
  if (a.first == b.first) {
    return a.second < b.second;
  }
  return a.first < b.first;
}
template <typename T>
bool desc(pair<T, T> &a, pair<T, T> &b) {
  if (a.first == b.first) {
    return a.second > b.second;
  }
  return a.first > b.first;
}
template <typename T>
T power(T a, T b) {
  if (b == 0) return 1;
  if (b == 1)
    return a;
  else {
    T res = (power(a, b / 2));
    if (b % 2) {
      return (res * res * a);
    } else {
      return res * res;
    }
  }
}
template <typename T>
T power(T a, T b, T modulo) {
  if (b == 0) return 1;
  if (b == 1)
    return a;
  else {
    T res = (power(a, b / 2, modulo) % modulo);
    if (b % 2) {
      return ((((res % modulo) * (res % modulo)) % modulo) * (a % modulo)) %
             modulo;
    } else {
      return ((res % modulo) * (res % modulo)) % modulo;
    }
  }
}
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T p, T q) {
  return (p * q) / gcd<T>(p, q);
}
template <typename T>
void primefactorise(T n, vector<T> &vec) {
  while (n % 2 == 0) {
    vec.emplace_back(2);
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      vec.emplace_back(i);
      n = n / i;
    }
  }
  if (n > 2) {
    vec.emplace_back(n);
  }
}
template <typename T>
void all_factor(T n, vector<T> &vec) {
  for (auto i = 1; i <= sqrt(n); ++i) {
    if (n % i == 0) {
      vec.emplace_back(i);
      if (i != (n / i)) {
        vec.emplace_back(n / i);
      }
    }
  }
}
long long mulmod(long long a, long long b, long long c) {
  if (b == 0) {
    return 0;
  }
  long long s = mulmod(a, b / 2, c);
  if (b % 2 == 1) {
    long long p = (a % c + 2 * (s % c)) % c;
    return p;
  } else {
    long long p = (2 * (s % c)) % c;
    return p;
  }
}
long long mod_inv(long long a) {
  return (power<long long>(a, mod - 2, mod)) % mod;
}
void factorial(long long n, vector<long long int> fact) {
  fact.resize(n + 1, 1);
  fact[0] = 1;
  fact[1] = 1;
  for (int i = 2; i <= n; ++i) {
    fact[i] = ((fact[i - 1] % mod) * (i % mod)) % mod;
  }
}
const int N = 1e5 + 2;
int a[N];
void update(int index, int val) {
  while (index < N) {
    a[index] += val;
    index += (index & (-index));
  }
}
long long sum(int index) {
  long long s = 0;
  while (index > 0) {
    s += a[index];
    index -= (index & (-index));
  }
  return s;
}
int main() {
  std::chrono::time_point<std::chrono::high_resolution_clock> start_timer,
      end_timer;
  start_timer = std::chrono::high_resolution_clock::now();
  bool show_time = false;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  memset(a, 0, sizeof(a));
  ;
  long long n;
  cin >> n;
  vector<long long int> v(n + 1);
  for (auto i = 1; i <= n; i++) {
    cin >> v[i];
  };
  map<long long, vector<long long int> > mp;
  for (int j = 1; j <= n; ++j) {
    update(j, v[j]);
    mp[v[j]].emplace_back(j);
  }
  long long q;
  cin >> q;
  while (q--) {
    long long s = 0;
    long long b, c;
    cin >> b >> c;
    for (auto &in : mp[b]) {
      update(in, c - b);
      mp[c].emplace_back(in);
    }
    mp.erase(mp.find(b));
    s = sum(1e5 + 1);
    cout << ((s)) << "\n";
    ;
  }
  end_timer = std::chrono::high_resolution_clock::now();
  long long elapsed_time =
      std::chrono::duration_cast<std::chrono::milliseconds>(end_timer -
                                                            start_timer)
          .count();
  if (show_time) {
    cout << "\nElapsed Time: " << elapsed_time << "ms\n";
  }
  return 0;
}
