#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long cost[n];
  long long cost_sort[n];
  for (int i = 0; i < n; i++) {
    cin >> cost[i];
    cost_sort[i] = cost[i];
  }
  sort(cost_sort, cost_sort + n);
  long long cm1[n];
  long long cm2[n];
  cm1[0] = cost[0];
  cm2[0] = cost_sort[0];
  for (int i = 1; i < n; i++) {
    cm1[i] = cost[i] + cm1[i - 1];
    cm2[i] = cost_sort[i] + cm2[i - 1];
  }
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int type;
    cin >> type;
    int l, m;
    cin >> l >> m;
    long long ans = 0;
    if (type == 1) {
      if (l != 1)
        ans += cm1[m - 1] - cm1[l - 2];
      else
        ans += cm1[m - 1];
    } else {
      if (l != 1)
        ans += cm2[m - 1] - cm2[l - 2];
      else
        ans += cm2[m - 1];
    }
    cout << ans << endl;
  }
  return 0;
}
