#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, j;
  cin >> n;
  long long int a[n], b[n], suma[n], sumb[n], sum = 0, sum2 = 0, t, l, r;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    suma[i] = sum + a[i];
    b[i] = a[i];
    sum = sum + a[i];
  }
  sort(b, b + n);
  cin >> m;
  for (i = 0; i < n; i++) {
    sumb[i] = sum2 + b[i];
    sum2 = sum2 + b[i];
  }
  for (j = 0; j < m; j++) {
    cin >> t >> l >> r;
    if (t == 1 && (l - 2) >= 0)
      cout << suma[r - 1] - suma[l - 2] << endl;
    else if (t == 1)
      cout << suma[r - 1] << endl;
    else if (t == 2 && (l - 2) >= 0)
      cout << sumb[r - 1] - sumb[l - 2] << endl;
    else
      cout << sumb[r - 1] << endl;
  }
}
