#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T amax(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T amin(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
const long long INF = 1e18;
const int32_t M = 1e9 + 7;
const int32_t MM = 998244353;
const unsigned long long N = 0;
void solve() {
  unsigned long long n, sum = 0;
  cin >> n;
  vector<unsigned long long> a, b, k;
  for (unsigned long long i = 0; i < n; i++) {
    unsigned long long c;
    cin >> c;
    sum += c;
    b.push_back(c);
    a.push_back(sum);
  }
  sum = 0;
  sort(b.begin(), b.end());
  for (unsigned long long i = 0; i < n; i++) {
    sum += b[i];
    k.push_back(sum);
  }
  unsigned long long m, ans;
  cin >> m;
  while (m--) {
    unsigned long long x, y, z;
    cin >> x >> y >> z;
    if (x == 1) {
      if (y == 1) {
        ans = a[z - 1];
      } else {
        ans = a[z - 1] - a[y - 2];
      }
    } else {
      if (y == 1) {
        ans = k[z - 1];
      } else {
        ans = k[z - 1] - k[y - 2];
      }
    }
    cout << ans << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  unsigned long long q = 1;
  while (q--) solve();
  return 0;
}
