#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
int n, m;
long long sorted[MAX];
long long notSorted[MAX];
long long getSum(int l, int r, int q) {
  if (q == 1) return notSorted[r] - notSorted[l - 1];
  return sorted[r] - sorted[l - 1];
}
int main() {
  cin >> n;
  vector<long long> ans;
  for (int i = 1; i <= n; i++) {
    cin >> notSorted[i];
    sorted[i] = notSorted[i];
  }
  sort(sorted, sorted + n + 1);
  for (int i = 1; i <= n; i++) {
    notSorted[i] += notSorted[i - 1];
    sorted[i] += sorted[i - 1];
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    int l, r, q;
    cin >> q >> l >> r;
    ans.push_back(getSum(l, r, q));
  }
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
