#include <bits/stdc++.h>   using namespace std;   template <class T>   void read(vector<T> &a, long long n) {     T x;     a.clear();     for (long long i = 0; i < n; i++) {       cin >> x;       a.push_back(x);     }   }   template <class T>   void write(vector<T> &a) {     for (T x : a) cout << x <<    ;     cout << endl;   }   const int N = 300005;   const int S = 500;   long long sum[S][S];   long long ans[N];   vector<pair<pair<int, int>, int> > q;   int n, m;   int w[N];   int main() {     ios_base::sync_with_stdio(0);     cin >> n;     for (int i = 1; i <= n; i++) cin >> w[i];     cin >> m;     for (int i = 0; i < m; i++) {       int a, b;       cin >> a >> b;       q.push_back(make_pair(make_pair(a, b), i));     }     sort(q.begin(), q.end());     reverse(q.begin(), q.end());     int pos = n;     for (int i = 0; i < q.size(); i++) {       int a = q[i].first.first;       int b = q[i].first.second;       int id = q[i].second;       while (pos >= a) {         for (int j = 1; j < S; j++) sum[j][pos % j] += w[pos];         pos--;       }       if (b < S)         ans[id] = sum[b][a % b];       else {         long long res = 0;         for (int j = a; j <= n; j += b) res += w[j];         ans[id] = res;       }     }     for (int i = 0; i < m; i++) cout << ans[i] << endl;   }   