#include <iostream>

using namespace std;

int main () {
    int t;
    cin >> t;
    while(t--) {
        unsigned long long n;
        cin >> n;
        if(n < 2) {
            cout << 0 << "\n";
            continue;
        }
        cout << 4 * (((n - 1) / 2) * ((n - 1) / 2 + 1) * ((n - 1) + 1) / 3) << "\n";

    }

    return 0;
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >> t;
    while(t--) {
        unsigned long long n;
        cin >> n;
        cout << 4 * n * (n+1) * (2*n + 1) / 3 << "\n";

    }

    return 0;
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >> t;
    while(t--) {
        unsigned long long n;
        cin >> n;
        n = (n - 1) / 2;
        cout << 4 * n * (n+1) * (2*n + 1) / 3 << "\n";
    }

    return 0;
}


#include <iostream>
using namespace std;
int main() {
    int t;
    cin >> t;
    for(int i = 0; i < t; i++) {
        long long n;
        cin >> n;
        long long k;
        k = (n - 1) / 2;

        cout << (n*n * k) - (k * (8*k*k - 2) / 6) << endl;
    }
}


#include <iostream>

using namespace std;

int main () {
    int t;
    cin >> t;
    while(t--) {
        unsigned long long n;
        cin >> n;
        cout << 4 * (((n - 1) / 2) * ((n - 1) / 2 + 1) * ((n - 1) + 1) / 3) << "\n";
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
int tt;
cin >> tt;
while(tt--)
{

int n;
cin >> n;
if(n == 1)
{
cout << 0 << endl;
goto hell;
}
if(n == 3)
{
cout << 8 << endl;
goto hell;
}
ll j = 2;
ll sum = 8;
ll now = 3;
while(now < n)
{
now += 2;
sum += (now*j)*2;
sum += ((now-2)*j)*2;
j++;
}
cout << sum << endl;

hell:;
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
int tt;
cin >> tt;
while(tt--)
{

int n;
cin >> n;
if(n == 1)
{
cout << 0 << endl;
goto hell;
}
if(n == 3)
{
cout << 8 << endl;
goto hell;
}
ll j = 2;
ll sum = 8;
ll now = 3;
while(now < n)
{
now += 2;
sum += (now*j)*2;
sum += ((now-2)*j)*2;
j++;
}
cout << sum << endl;
}
hell:;

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
int tt;
cin >> tt;
while(tt--)
{

int n;
cin >> n;
if(n == 1) cout << 0 << endl;
if(n == 3)
cout << 8 << endl;
ll j = 2;
ll sum = 8;
ll now = 3;
while(now < n)
{
now += 2;
sum += (now*j)*2;
sum += ((now-2)*j)*2;
j++;
}
cout << sum << endl;
}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
int tt;
cin >> tt;
while(tt--)
{

int n;
cin >> n;
if(n == 1)
{
cout << 0 << endl;
goto hell;
}
if(n == 3)
{
cout << 8 << endl;
goto hell;
}
ll j = 2;
ll sum = 8;
ll now = 3;
while(now < n)
{
now += 2;
sum += (now*j)*2;
sum += ((now-2)*j)*2;
j++;
}
cout << sum << endl;
}
hell;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long int

int main()
{
int tt;
cin >> tt;
while(tt--)
{

ll j = 2;
ll sum = 8;
ll now = 3;

int n;
cin >> n;
if(n == 1)
{
cout << 0 << endl;
goto hell;
}
if(n == 3)
{
cout << 8 << endl;
goto hell;
}
while(now < n)
{
now += 2;
sum += (now*j)*2;
sum += ((now-2)*j)*2;
j++;
}
cout << sum << endl;

hell:;
}

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){
    ll n;
    cin>>n;
    cout<<(((n*n)-1)/3)*n  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){

    double  n;
    unsigned long long z;

    cin>>n;

    z=(((n*n)-1)/3)*n;

    cout<<z  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){
    double n;
    int x;
    cin>>n;
    x=(((n*n)-1)/3)*n;
    cout<<x  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){

    double  n;
    unsigned long long z;

    cin>>n;

    z=(n*(n+1)*(n-1))/3;

    cout<<z  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){
    double n;
    double x;
    ll z;
    cin>>n;

    x=(((n*n)-1)/3)*n;
    z=x;

    cout<<z  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){
    double n,x;
    cin>>n;
    x=(((n*n)-1)/3)*n;
    int z=x;

    cout<<z  nw;
    }

}


#include <iostream>

#include <deque>

#include <stdio.h>

#include<bits/stdc++.h>

#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define sp <<" "<<
#define nw <<"\n"
#define case "Case "<<tc++<<": "
#define IOS ios_base::sync_with_stdio(0);cin.tie(0)
#define LL long long int
#define ull unsigned LL

const int inf=1<<30;
const LL INF=1e18;
const int MOD=1e9+7;
const int maxn = 1e5+10;

using namespace std;
typedef long long ll;

/*int ck_prime(int n)
{
    int coun,ck=0;
     coun=0;
     if(n>1){
      for(int i=2;i*i<=n;i++){
        if( n%i==0 ){
            coun++;    // the number is not prime. and it is divasable by  i.
            return i;
            break;
          }
        }
      }
     if(n==1){
       coun=coun;
         }
    if(coun==0){
        //ck=1;      // the number is prime.
        return n;
     }
}

//int lcm(int a,int b){

//     return (a*b)/gcd(a,b);

//}*/

int main(){
    int Tc,tc=1;
    cin>>Tc;
    while(Tc>=tc++){
    double n;
    cin>>n;
    cout<<(((n*n)-1)/3)*n  nw;
    }

}


#include <iostream>
using namespace std;

int main(){
   int t;cin>>t;
   while(t--){
      int n;cin>>n;
      long long ans=0;
      for(int i=1;i<=n;i+=2){
         ans+=2*(i-1)*(i-1);
      }
      cout<<ans<<endl;
   }
}


#include <iostream>
using namespace std;

int main(){
   int t;cin>>t;
   while(t--){
      long long ans=0;
      for(int i=1;i<=n;i+=2){
         ans+=2*(i-1)*(i-1);
      }
      cout<<ans<<endl;
   }
}


#include <iostream>
using namespace std;

int main(){
   int t;cin>>t;
   while(t--){
      int n;cin>>n;
      long long ans=0;
      for(int i=1;i<=n;i+=2){
         ans+=(i-1)*(i-1);
      }
      cout<<2*ans<<endl;
   }
}


#include <iostream>
using namespace std;

int main(){
   int t;cin>>t;
   while(t--){
      long long n;cin>>n;
      long long ans=0;
      for(long long i=1;i<=n;i+=2){
         ans+=2*(i-1)*(i-1);
      }
      cout<<ans<<endl;
   }
}


#include <iostream>
using namespace std;

int main(){
   int t;cin>>t;
   while(t--){
      int n;cin>>n;
      long long ans=0;
      for(long i=1;i<=n;i+=2){
         ans+=2*(i-1)*(i-1);
      }
      cout<<ans<<endl;
   }
}


#include <iostream>
using namespace std;
int main(){
    long long t,n,sum,count=0;
    cin>>t;
    for(int i=0;i<t;i++){
    	sum=0;
        cin>>n;
        int m=n/2;
        for(int j=0;j<m;j++){
            if(j==0){
            	sum+=m;
			}
			else{
				long long a=j*(j+1),b=(m-j)*3;
				sum+=a+b;
			}
        }
        long long a=m*(m+1)*2;
        cout<<sum*4+a<<endl;
    }
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;
int main(){
    ll t,n,sum;
    cin>>t;
    for(ll i=0;i<t;i++){
    	sum=0;
        cin>>n;
        for(ll j=3;j<=n;j=j+2){
        	ll tmp=j/2;
        	sum+=tmp*4*(j-1);
		}
		cout<<sum<<"\n";
    }
    return 0;
}


#include <iostream>
#define ll long long
using namespace std;
int main(){
    ll t,n,sum;
    cin>>t;
    for(ll i=0;i<t;i++){
    	sum=0;
        cin>>n;
        for(ll j=3;j<=n;j=j+2){

        	sum+=(j/2)*4*(j-1);
		}
		cout<<sum<<"\n";
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    long long t,n,sum;
    cin>>t;
    for(long long i=0;i<t;i++){
    	sum=0;
        cin>>n;
        long long m=n/2;
        for(long long j=0;j<m;j++){
            if(j==0){
            	sum+=m;
			}
			else{
				sum+=j*(j+1)+(m-j)*(2*j+1);
			}
        }
        cout<<sum*4+(m+1)*m*2<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    long long t,n,sum,count=0;
    cin>>t;
    for(int i=0;i<t;i++){
    	sum=0;
        cin>>n;
        int m=n/2;
        for(int j=0;j<m;j++){
            if(j==0){
            	sum+=m;
			}
			else{
				sum+=j*(j+1)+(m-j)*3;
			}
        }
        cout<<sum*4+m*(m+1)*2<<endl;
    }
    return 0;
}


#include <iostream>
using namespace std;
int main(){
    long long t,n,sum,count=0;
    cin>>t;
    for(long long i=0;i<t;i++){
    	sum=0;
        cin>>n;
        long long m=n/2;
        for(long long j=0;j<m;j++){
            if(j==0){
            	sum+=m;
			}
			else{
				sum+=j*(j+1)+(m-j)*3;
			}
        }
        cout<<sum*4+(m+1)*m*2<<endl;
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int t,n; cin>>t;
    while(t--) { cin>>n; long long ans=(n*(n+1)*(n-1))/3; cout<<ans<<endl;}
}


#include<iostream>
using namespace std;
int main()
{
    long long t,n; cin>>t;
    while(t--) { cin>>n; cout<<(n*(n+1)*(n-1))/3<<endl;}
}


#include<iostream>
using namespace std;
int main()
{
    int t,n; cin>>t;
    while(t--)
    {
        cin>>n;
        long long ans=0;
        n=(n-1)/2;
        ans += (n*n*(n+1));
        ans += n*(n+1)*(n+1);
        ans/=6;
        ans*=8;
        cout<<ans<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
    long long t,n; cin>>t;
    while(t--)
    {
        cin>>n;
        long long ans=0;
        n=(n-1)/2;
        ans += (n*n*(n+1));
        ans += n*(n+1)*(n+1);
        ans/=6;
        ans*=8;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define li long int
#define ull unsigned long long

void fast_IO() { ios_base::sync_with_stdio(false);cin.tie(NULL);}
void test_here_once(){ freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);}

void fun()
{
	ll n; cin>>n;

	if(n==1){cout<<0<<endl; return;}

	ll sum=0;
	for(int i=3;i<=n;i+=2)
	{
		int moves=i/2;
		sum+=(i-1)*4*moves;
	}
	cout<<sum<<endl;
}

int main()
{
	//test_here_once();
	fast_IO();

	//fun();
	int t; cin>>t;
	while(t--)
	{
		fun();
	}
}


#include <cassert>
#include <complex>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <limits>
#include <numeric>
#include <sstream>
#include <utility>

#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#include <memory.h>
//#include "bigint.h"

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define init(st) memset(st, 0, sizeof(st))
#define ll long long

// String operations
template<class T>
void splitstr(const string &s, vector<T> &out) {
    istringstream in(s);
    out.clear();
    copy(istream_iterator<T>(in), istream_iterator<T>(), back_inserter(out));
}

template<class T>
T read_value(string s) {
    T result;
    istringstream sin(s);
    sin >> result;
    return result;
}

#define read_int(s) read_value<int>(s)
#define read_ll(s) read_value<ll>(s)
#define read_float(s) read_value<float>(s)
#define read_double(s) read_value<double>(s)

string read_line() {
    string ret_val;
    getline(std::cin, ret_val);
    return ret_val;
}

template<class T>
void init_array(T *arr, int size, T value) {
    for (int i = 0; i < size; i++)
        arr[i] = value;
}

// Arithmetic operations
template<class T>
inline T gcd(T a, T b) {
    return (!a) ? b : gcd(b % a, a);
}

template<class T>
inline T mod(T a, T p) {
    a %= p;
    return (a < 0) ? a + p : a;
}

template<class T>
inline int num_bits(T n) {
    return (!n) ? 0 : 1 + numbits(n & (n - 1));
}

template<class T>
inline T inverse(T a, T m) {
    a = mod<T>(a,m);
    return (a==1) ? 1 : mod((1-m*inverse(m%a,a))/a,m);
}

template<class T>
inline bool is_prime(T a) {
    T lim = (T)sqrt((double)a);
    for (T i = 2; i <= T(lim+1E-9); i++)
        if (a % i == 0)
           return false;
    return true;
}

template<class T>
inline T power(T a, T p, T mod) {
    if (!p) return 1;
    T temp = power(a, p>>1, mod);
    temp = (temp * temp) % mod;
    if (p&1)
        temp = (temp * a) % mod;
    return temp;
}

void get_primes(int start, int end, vector<int> &vi) {
    int *p = new int[end + 1];
    init_array<int>(p, end+1, 0); p[1] = 1;
    for (int i = 2; i <= end; i++) {
            if (!p[i]) {
                    if (i >= start)
                            vi.push_back(i);
                    for (int j = 2*i; j <= end; j += i)
                            p[j] = 1;
            }
    }
    delete [] p;
}

// Graph operations
bool dfs(int current, int final, int total, int* visited, int **edges, bool flow) {
    if (current == final)
            return true;
    if (visited[current])
            return false;
    visited[current] = true;
    for (int i = 0; i < total; i++)
            if (edges[current][i] && dfs(i, final, total, visited, edges, flow)) {
                    if (flow) {
                            edges[current][i]--;
                            edges[i][current]++;
                    }
                    return true;
            }
    return false;
}

int flow(int in, int out, int total, int **edges) {
    int result = 0;
    int *visited = new int[total];
    while (init_array<int>(visited, total, 0), dfs(in, out, total, visited, edges, true))
            result++;
    delete [] visited;
    return result;
}

// Disjoint datasets
void create_set(int x, int *P, int *rank) {
        P[x] = x;
        rank[x] = 0;
}

int find_set(int x, int *P) {
        if (x != P[x])
                P[x] = find_set(P[x], P);
        return P[x];
}

bool merge_sets(int x, int y, int *P, int *rank) {
        int Px = find_set(x, P);
        int Py = find_set(y, P);
        if(Px == Py)
                return false;
        if (rank[Px] > rank[Py]) P[Py] = Px;
        else P[Px] = Py;
        if (rank[Px] == rank[Py])
                rank[Py]++;
        return true;
}

// Binary tree operations
template <typename T>
int read_cum_freq(int index, T *tree) {
        int sum = 0;
        while (index) {
                sum += tree[index];
                index -= (index & -index);
        }
        return sum;
}

template <typename T>
void upd_freq(int index, int mxIndex, int value, T *tree) {
        while (index <= mxIndex) {
                tree[index] += value;
                index += (index & -index);
        }
}

template <typename T>
int read_freq(int index, T *tree) {
        return read_cum_freq(index, tree) - read_cum_freq(index-1, tree);
}

// String algos.
void build_failure_function(const string &str, int *temp_arr) {
    temp_arr[0] = temp_arr[1] = 0;
    for (int i = 2; i <= sz(str); i++) {
        temp_arr[i] = -1;
        for (int ind = temp_arr[i-1]; temp_arr[i] == -1; ind = temp_arr[ind]) {
            if (str[ind] == str[i-1]) {
                temp_arr[i] = ind + 1;
            } else if (ind == 0) {
                temp_arr[i] = 0;
            }
        }
    }
}

void KMP(const string &text, const string &pattern, int *res) {
    int *temp_arr = new int[sz(pattern) + 1];
    build_failure_function(pattern, temp_arr);
    int i = 0;
    int ind = 0;
    while (i < sz(text)) {
        if (text[i] == pattern[ind]) {
            res[i] = ++ind;
            if (res[i] == sz(pattern)) {
                ind = temp_arr[ind];
            }
            i++;
        } else if (ind == 0) {
            res[i++] = 0;
        } else {
            ind = temp_arr[ind];
        }
    }
    delete [] temp_arr;
}

template <typename T, int N>
struct matrix {
    T m[N][N];
    T md;

    matrix(T md, bool unary = false) {
        this->md = md;
        init(m);
        if (unary) {
            for (int i = 0; i < N; i++) {
                m[i][i] = 1;
            }
        }
    }

    matrix operator*(const matrix &that) const {
        matrix ret_val(md, false);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                for (int k = 0; k < N; k++) {
                    ret_val.m[i][j] += this->m[i][k] * that.m[k][j];
                    ret_val.m[i][j] %= md;
                }
            }
        }
        return ret_val;
    }

    vector<T> operator*(const vector<T> &vec) const {
        vector<T> ret_val(vec.size(), 0);
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                ret_val[i] += m[i][j] * vec[j];
                ret_val[i] %= md;
            }
        }
        return ret_val;
    }

    matrix power(int pw) const {
        if (!pw) {
            return matrix(md, true);
        }
        if (pw == 1) {
            return *this;
        }
        matrix ret_val = power(pw>>1);
        ret_val = ret_val * ret_val;
        if (pw & 1) {
            ret_val = ret_val * (*this);
        }
        return ret_val;
    }
};

// Setup
void setup(int value, string name) {
    string name_in = name + ".in";
    string name_out = name + ".out";
    freopen(name_in.c_str(), "r", stdin);
    if (value) {
        freopen(name_out.c_str(), "w", stdout);
    }
}

struct R {
    int a;
    int b;
    int i;
    ll tot;

    int pos() const {
        return a % b;
    }

    bool operator<(const R& that) const {
        if (this->b != that.b)
            return this->b < that.b;
        if (this->pos() != that.pos())
            return this->pos() < that.pos();
        return this->a < that.a;
    }
};

struct cmp {
    bool operator()(const R& lhs, const R& rhs) const {
        return lhs.i < rhs.i;
    }
};

int main() {
#ifdef LOCAL_HOST
    setup(0, "temp");
#endif
    int n; std::cin >> n;
    vector<int> vl(n);
    for (int i = 0; i < n; ++i) scanf("%d", &vl[i]);
    int p; std::cin >> p;
    vector<R> vr(p);
    for (int i = 0; i < p; ++i) {
        scanf("%d %d", &vr[i].a, &vr[i].b);
        --vr[i].a;
        vr[i].i = i;
        vr[i].tot = 0;
    }

    sort(vr.begin(), vr.end());
    for (int i = 0; i < vr.size(); ++i) {
        int last = i;
        while (last < vr.size() && vr[i].b == vr[last].b && vr[i].pos() == vr[last].pos())
            ++last;
        --last;
        int tmp = last;
        int a = vr[i].a;
        int b = vr[i].b;
        for (int j = ((n-a-1) / b) * b + a; j >= a; j -= b) {
            vr[last].tot += vl[j];
            while (last != i && vr[last-1].a == j) {
                --last;
                vr[last].tot = vr[last+1].tot;
            }
        }
        i = tmp;
    }

    sort(vr.begin(), vr.end(), cmp());
    for (int i = 0; i < p; ++i)
        std::cout << vr[i].tot << std::endl;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct zap
{int a,b,n;};
bool f(zap a,zap b)
{return a.b<b.b;}
int n,p,a[300001],q;
long long ans[300001],d[300001];
zap c[300000];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	scanf("%d",&p);
	for (int i=0;i<p;i++)
	{
		scanf("%d%d",&c[i].a,&c[i].b);
		c[i].n=i+1;
	}
	sort(c,c+p,f);
	q=int(sqrt(double(n)));
	for (int i=0;i<p;i++)
	{
		if (c[i].b<q)
		{
			if (c[i].b!=c[i-1].b)
			{
				for (int j=n;j>0;j--)
					if (j+c[i].b>n) d[j]=a[j];
					else d[j]=a[j]+d[j+c[i].b];
			}
			ans[c[i].n]=d[c[i].a];
		}
		else
		{
			int j=c[i].a;
			ans[c[i].n]+=a[j];
			while(j+c[i].b<=n)
			{
				j+=c[i].b;
				ans[c[i].n]+=a[j];
			}
		}
	}
	for (int i=1;i<=p;i++) printf("%I64d\n",ans[i]);
}


#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
struct zap
{int a,b,n;};
bool f(zap a,zap b)
{return a.b<b.b;}
int n,p,a[100001],q;
long long ans[100001],d[100001];
zap c[100000];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	scanf("%d",&p);
	for (int i=0;i<p;i++)
	{
		scanf("%d%d",&c[i].a,&c[i].b);
		c[i].n=i+1;
	}
	sort(c,c+p,f);
	q=int(sqrt(double(n)));
	for (int i=0;i<p;i++)
	{
		if (c[i].b<q)
		{
			if (c[i].b!=c[i-1].b)
			{
				for (int j=n;j>0;j--)
					if (j+c[i].b>n) d[j]=a[j];
					else d[j]=a[j]+d[j+c[i].b];
			}
			ans[c[i].n]=d[c[i].a];
		}
		else
		{
			int j=c[i].a;
			ans[c[i].n]+=a[j];
			while(j+c[i].b<=n)
			{
				j+=c[i].b;
				ans[c[i].n]+=a[j];
			}
		}
	}
	for (int i=1;i<=p;i++) printf("%I64d\n",ans[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <cstring>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 400100;
const int SQ = 550;

int n, m, S;
int64 w[MAXN], ans[MAXN], s[MAXN];
vector<pair<int, int> > q[SQ][SQ];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    cin >> n;
    S = max(2, (int)sqrt(n + 1.0));
    cerr << S << endl;
    forn(i, n)
        scanf("%I64d", &w[i]);

    cin >> m;
    forn(i, m) {
        int a, b;
        scanf("%d%d", &a, &b);
        a--;

        if (b >= S)
            for(int j = a; j < n; j += b)
                ans[i] += w[j];
        else
            q[b][a % b].pb(mp(a, i));
    }

    for(int d = 1; d < SQ; d++)
        forn(mod, d) {
            if (q[d][mod].empty()) continue;

            int size = 1;
            s[0] = 0;
            for(int i = mod; i < n; i += d) {
                s[size] = s[size - 1] + w[i];
                size++;
            }

            forn(i, q[d][mod].size()) {
                int a = q[d][mod][i].first, id = q[d][mod][i].second;
                ans[id] = s[size - 1] - s[a / d];
            }
        }

    forn(i, m)
        printf("%I64d\n", ans[i]);

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <cstring>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 100100;
const int SQ = 550;

int n, m, S;
int64 w[MAXN];
vector<int64> s[SQ][SQ];

int64 solve(int a, int b) {
    if (b >= S) {
        int64 ans = 0;
        for(int i = a; i < n; i += b) ans += w[i];
        return ans;
    }

    return s[b][a % b].back() - s[b][a % b][a / b];
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    cin >> n;
    S = (int)sqrt(n + 1.0);
    forn(i, n)
        scanf("%I64d", &w[i]);

    for(int d = 1; d < S; d++) {
        forn(i, d)
            s[d][i].pb(0);

        forn(i, n) {
            int mod = i % d;
            vector<int64> &v = s[d][mod];
            v.pb(v.back() + w[i]);
        }
    }

    cin >> m;
    forn(i, m) {
        int a, b;
        scanf("%d%d", &a, &b);
        printf("%I64d\n", solve(a - 1, b));
    }

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#pragma comment(linker, "/STACK:64000000")

#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <utility>
#include <memory.h>
#include <cstring>

#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>

#include <iostream>
#include <sstream>

using namespace std;

typedef long long int64;

#define forn(i, n) for(int i = 0; i < (int)(n); i++)
#define ford(i, n) for(int i = (int)(n) - 1; i >= 0; i--)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()

const int INF = (int)1E9;
const int64 INF64 = (int64)1E18;
const long double EPS = 1E-8;
const long double PI = 3.1415926535897932384626433832795;

const int MAXN = 400100;
const int SQ = 550;

int n, m, S;
int64 w[MAXN], ans[MAXN];
vector<int64> s[SQ];
vector<pair<int, int> > q[MAXN];

int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "wt", stdout);
#endif

    cin >> n;
    S = max(2, (int)sqrt(n + 1.0));
    cerr << S << endl;
    forn(i, n)
        scanf("%I64d", &w[i]);

    cin >> m;
    forn(i, m) {
        int a, b;
        scanf("%d%d", &a, &b);
        if (b >= S)
            for(int j = a - 1; j < n; j += b)
                ans[i] += w[j];
        else
            q[b].pb(mp(a - 1, i));
    }

    for(int d = 1; d < SQ; d++) {
        if (q[d].empty()) continue;

        forn(i, d) {
            swap(s[i], vector<int64>());
            s[i].pb(0);
        }

        forn(i, n) {
            vector<int64> &v = s[i % d];
            v.pb(v.back() + w[i]);
        }

        forn(i, q[d].size()) {
            int a = q[d][i].first, id = q[d][i].second;
            ans[id] = s[a % d].back() - s[a % d][a / d];
        }
    }

    forn(i, m)
        printf("%I64d\n", ans[i]);

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <memory.h>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define sz(x) static_cast<int>(x.size())
typedef long long int64;

template<class T> T sqr(const T& t) {return t * t;}
template<class T> T abs(const T& t) {return ((t > 0) ? (t) : (-t));}

void initialize()
{
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
}

struct Point
{
    int x;
    int y;
    Point(int x_, int y_): x(x_), y(y_)
    { }
};

const int W = 2000;
const int MAXS = 300;
const int MAX = 3 * (int)1e5 + 10;
int w[MAX];
vector<int64> precalc[(MAX / W) + 1][MAXS];

int n;
void calc() {
    for (int i = 0; i <= n / W; ++i) {
        int start = i * W;
        for (int b = 1; b < MAXS; ++b) {
            precalc[i][b].resize(b);
            for (int s = 0; s < b; ++s) {
                int64 res = 0;
                for (int k = start + s; k < start + W && k < n; k += b) {
                    res += w[k];
                }
                precalc[i][b][s] = res;
            }
        }
    }
}

int main()
{
    //initialize();

    cerr << "Reading...\n";
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }

    cerr << "Precalcing...\n";
    calc();

    cerr << "Working...\n";
    int q;
    cin >> q;
    cerr << "q = " << q << endl;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        //cerr << a << b;
        a -= 1;
        int64 res = 0;
        if (b >= MAXS) {
            for (int i = a; i < n; i += b) {
                res += w[i];
            }
        }
        else {
            int64 ind = a / W;
            for (int j = a; j < (ind + 1) * W && j < n; j += b) {
                res += w[j];
            }
            for (int i = ind + 1; i <= n / W; ++i) {
                int start = i * W;
                int pos = a + ((start - a) / b) * b;
                while (pos < start) {
                    pos += b;
                }
                res += precalc[i][b][pos - start];
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <memory.h>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define sz(x) static_cast<int>(x.size())
typedef long long int64;

template<class T> T sqr(const T& t) {return t * t;}
template<class T> T abs(const T& t) {return ((t > 0) ? (t) : (-t));}

void initialize()
{
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
}

struct Point
{
    int x;
    int y;
    Point(int x_, int y_): x(x_), y(y_)
    { }
};

const int W = 2000;
const int MAXS = 300;
const int MAX = 3 * (int)1e5 + 10;
int w[MAX];
vector<int64> precalc[(MAX / W) + 1][MAXS];

int n;
void calc() {
    for (int i = 0; i <= n / W; ++i) {
        int start = i * W;
        for (int b = 1; b < MAXS; ++b) {
            precalc[i][b].resize(b);
            for (int s = 0; s < b; ++s) {
                int64 res = 0;
                for (int k = start + s; k < start + W; k += b) {
                    res += w[k];
                }
                precalc[i][b][s] = res;
            }
        }
    }
}

int main()
{
    //initialize();

    cerr << "Reading...\n";
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }

    cerr << "Precalcing...\n";
    calc();

    cerr << "Working...\n";
    int q;
    cin >> q;
    cerr << "q = " << q << endl;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        //cerr << a << b;
        a -= 1;
        int64 res = 0;
        if (b >= MAXS) {
            for (int i = a; i < n; i += b) {
                res += w[i];
            }
        }
        else {
            int64 ind = a / W;
            for (int j = a; j < (ind + 1) * W && j < n; j += b) {
                res += w[j];
            }
            for (int i = ind + 1; i <= n / W; ++i) {
                int start = i * W;
                int pos = a + ((start - a) / b) * b;
                while (pos < start) {
                    pos += b;
                }
                res += precalc[i][b][pos - start];
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <memory.h>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define sz(x) static_cast<int>(x.size())
typedef long long int64;

template<class T> T sqr(const T& t) {return t * t;}
template<class T> T abs(const T& t) {return ((t > 0) ? (t) : (-t));}

void initialize()
{
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
}

struct Point
{
    int x;
    int y;
    Point(int x_, int y_): x(x_), y(y_)
    { }
};

const int W = 1000;
const int MAXS = 300;
const int MAX = 3 * (int)1e5 + 10;
int w[MAX];
vector<int64> precalc[MAX / W][MAXS];

int n;
void calc() {
    for (int i = 0; i <= n / W; ++i) {
        int start = i * W;
        for (int b = 1; b < MAXS; ++b) {
            for (int s = 0; s < b; ++s) {
                int64 res = 0;
                for (int k = start + s; k < start + W; k += b) {
                    res += w[k];
                }
                precalc[i][b].pb(res);
            }
        }
    }
}

int main()
{
    //initialize();

    cerr << "Reading...\n";
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }

    cerr << "Precalcing...\n";
    calc();

    cerr << "Working...\n";
    int q;
    cin >> q;
    cerr << "q = " << q << endl;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        //cerr << a << b;
        a -= 1;
        int64 res = 0;
        if (b >= MAXS) {
            for (int i = a; i < n; i += b) {
                res += w[i];
            }
        }
        else {
            int64 ind = a / W;
            for (int j = a; j < (ind + 1) * W && j < n; j += b) {
                res += w[j];
            }
            for (int i = ind + 1; i <= n / W; ++i) {
                int start = i * W;
                int pos = a + ((start - a) / b) * b;
                while (pos < start) {
                    pos += b;
                }
                res += precalc[i][b][pos - start];
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <memory.h>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define sz(x) static_cast<int>(x.size())
typedef long long int64;

template<class T> T sqr(const T& t) {return t * t;}
template<class T> T abs(const T& t) {return ((t > 0) ? (t) : (-t));}

void initialize()
{
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
}

struct Point
{
    int x;
    int y;
    Point(int x_, int y_): x(x_), y(y_)
    { }
};

const int W = 2000;
const int MAXS = 300;
const int MAX = 3 * (int)1e5 + 10;
int w[MAX];
vector<int64> precalc[MAX / W][MAXS];

int n;
void calc() {
    for (int i = 0; i <= n / W; ++i) {
        int start = i * W;
        for (int b = 1; b < MAXS; ++b) {
            precalc[i][b].resize(b);
            for (int s = 0; s < b; ++s) {
                int64 res = 0;
                for (int k = start + s; k < start + W; k += b) {
                    res += w[k];
                }
                precalc[i][b][s] = res;
            }
        }
    }
}

int main()
{
    //initialize();

    cerr << "Reading...\n";
    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }

    cerr << "Precalcing...\n";
    calc();

    cerr << "Working...\n";
    int q;
    cin >> q;
    cerr << "q = " << q << endl;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        //cerr << a << b;
        a -= 1;
        int64 res = 0;
        if (b >= MAXS) {
            for (int i = a; i < n; i += b) {
                res += w[i];
            }
        }
        else {
            int64 ind = a / W;
            for (int j = a; j < (ind + 1) * W && j < n; j += b) {
                res += w[j];
            }
            for (int i = ind + 1; i <= n / W; ++i) {
                int start = i * W;
                int pos = a + ((start - a) / b) * b;
                while (pos < start) {
                    pos += b;
                }
                res += precalc[i][b][pos - start];
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <memory.h>
#include <set>
#include <map>
#include <cstdio>
#include <cassert>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define mp(x, y) make_pair(x, y)
#define sz(x) static_cast<int>(x.size())
typedef long long int64;

template<class T> T sqr(const T& t) {return t * t;}
template<class T> T abs(const T& t) {return ((t > 0) ? (t) : (-t));}

void initialize()
{
    freopen("_.in", "r", stdin);
    freopen("_.out", "w", stdout);
}

struct Point
{
    int x;
    int y;
    Point(int x_, int y_): x(x_), y(y_)
    { }
};

const int W = 1000;
const int MAXS = 300;
const int MAX = 3 * (int)1e5 + 10;
int w[MAX];
vector<int64> precalc[MAX / W][MAXS];

int n;
void calc() {
    for (int i = 0; i <= n / W; ++i) {
        int start = i * W;
        for (int b = 1; b < MAXS; ++b) {
            for (int s = 0; s < b; ++s) {
                int64 res = 0;
                for (int k = start + s; k < start + W; k += b) {
                    res += w[k];
                }
                precalc[i][b].pb(res);
            }
        }
    }
}

int main()
{
    //initialize();

    cin >> n;
    for (int i = 0; i < n; ++i) {
        scanf("%d", &w[i]);
    }

    calc();

    int q;
    cin >> q;
    cerr << "q = " << q << endl;
    for (int i = 0; i < q; ++i) {
        int a, b;
        cin >> a >> b;
        //cerr << a << b;
        a -= 1;
        int64 res = 0;
        if (b >= MAXS) {
            for (int i = a; i < n; i += b) {
                res += w[i];
            }
        }
        else {
            int64 ind = a / W;
            for (int j = a; j < (ind + 1) * W && j < n; j += b) {
                res += w[j];
            }
            for (int i = ind + 1; i <= n / W; ++i) {
                int start = i * W;
                int pos = ((start - a) / b) * b;
                while (pos < start) {
                    pos += b;
                }
                res += precalc[i][b][pos - start];
            }
        }
        cout << res << "\n";
    }

    return 0;
}


#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>

using namespace std;

//***********zjut_DD for Topcoder***********
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef pair<int64,int64> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef map<string,int> MSI;
typedef map<string,string> MSS;
#define PB push_back
#define ALL(v) v.begin(),v.end()
#define Clear(buf,val) memset(buf,val,sizeof(buf)) //clear memory
#define Forl(i,s,t) for(int i=s;i< t;i++) //less   [s,t)
#define Fore(i,s,t) for(int i=s;i<=t;i++) //equal  [s,t]
#define Ford(i,t,s) for(int i=t;i>=s;i--) //down [s,t] t->s
#define Forv(i,v) for(int i=0;i<(int)v.size();i++)  //vector
#define Fors(i,s) for(int i=0;i<(int)s.length();i++)//string
//******************************************
#define maxn 630005
int n,Q,a[maxn];
int64 ans[maxn];
int seg;

struct QQ{
	int a,b,id;
	bool operator<(const QQ &s)const{
		return b<s.b;
	}
}qq[maxn];

int buf[maxn],*ptr;
int64 sum[maxn],*pts;
struct DD{
	int *b,len;
	int64 *s;
}dd[maxn];

int main(){
	while( scanf("%d",&n)!=EOF ){
		for(int i=1;i<=n;i++) scanf("%d",a+i);
		scanf("%d",&Q);
		for(int i=1;i<=Q;i++){
			scanf("%d%d",&qq[i].a,&qq[i].b);
			qq[i].id=i;
		}
		sort(qq+1,qq+1+Q);

		int seg=(int)(sqrt(n*1.0)+0.5);

		for(int i=1,cur=0;i<=Q;i++){
			if( qq[i].b>=seg ){
				int64 s=0;
				for(int j=qq[i].a;j<=n;j+=qq[i].b ){
					s+=a[j];
				}
				ans[ qq[i].id ]=s;
				continue;
			}
			if( qq[i].b !=cur ){
				cur=qq[i].b;
				ptr=buf;
				pts=sum;
				for(int j=1;j<=cur;j++){
					dd[j].b=ptr;
					dd[j].s=pts;
					for(int k=j;k<=n;k+=cur){
						*ptr=a[k];
						ptr++;
					}
					dd[j].len=ptr-dd[j].b;
					pts+=dd[j].len;
					*dd[j].s=*dd[j].b;
					for(int k=1;k<dd[j].len;k++){
						dd[j].s[k]=dd[j].s[k-1]+dd[j].b[k];
					}
				}
			}
			int f=qq[i].a % cur;
			if( f==0 ) f=cur;
			int bas=(qq[i].a-1)/cur;
			if( bas==0 )
				ans[ qq[i].id ]= dd[f].s[ dd[f].len-1 ];
			else
				ans[ qq[i].id ]= dd[f].s[ dd[f].len-1 ]- dd[f].s[bas-1];
		}
		for(int i=1;i<=Q;i++) printf("%I64d\n",ans[i]);
	}
}


#include <vector>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <string>

using namespace std;

//***********zjut_DD for Topcoder***********
typedef long long int64;
typedef unsigned long long uint64;
typedef pair<int,int> PII;
typedef pair<int64,int64> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VPII;
typedef map<string,int> MSI;
typedef map<string,string> MSS;
#define PB push_back
#define ALL(v) v.begin(),v.end()
#define Clear(buf,val) memset(buf,val,sizeof(buf)) //clear memory
#define Forl(i,s,t) for(int i=s;i< t;i++) //less   [s,t)
#define Fore(i,s,t) for(int i=s;i<=t;i++) //equal  [s,t]
#define Ford(i,t,s) for(int i=t;i>=s;i--) //down [s,t] t->s
#define Forv(i,v) for(int i=0;i<(int)v.size();i++)  //vector
#define Fors(i,s) for(int i=0;i<(int)s.length();i++)//string
//******************************************
#define maxn 630005
int n,Q,a[maxn];
int64 ans[maxn];
int seg;

struct QQ{
	int a,b,id;
	bool operator<(const QQ &s)const{
		return b<s.b;
	}
}qq[maxn];

int buf[maxn],*ptr;
int64 sum[maxn],*pts;
struct DD{
	int *b,len;
	int64 *s;
}dd[maxn];

int main(){
	while( scanf("%d",&n)!=EOF ){
		for(int i=1;i<=n;i++) scanf("%d",a+i);
		scanf("%d",&Q);
		for(int i=1;i<=Q;i++){
			scanf("%d%d",&qq[i].a,&qq[i].b);
			qq[i].id=i;
		}
		sort(qq+1,qq+1+Q);

		int seg=(int)(sqrt(n*1.0)+0.5);

		for(int i=1,cur=0;i<=Q;i++){
			if( qq[i].b>=seg ){
				int64 s=0;
				for(int j=qq[i].a;j<=n;j+=qq[i].b ){
					s+=a[j];
				}
				ans[ qq[i].id ]=s;
				continue;
			}
			if( qq[i].b !=cur ){
				cur=qq[i].b;
				ptr=buf;
				pts=sum;
				for(int j=1;j<=cur;j++){
					dd[j].b=ptr;
					dd[j].s=pts;
					for(int k=j;k<=n;k+=cur){
						*ptr=a[k];
						ptr++;
					}
					dd[j].len=ptr-dd[j].b;
					*dd[j].s=*dd[j].b;
					for(int k=1;k<dd[j].len;k++){
						dd[j].s[k]=dd[j].s[k-1]+dd[j].b[k];
					}
				}
			}
			int f=qq[i].a % cur;
			if( f==0 ) f=cur;
			int bas=(qq[i].a-1)/cur;
			if( bas==0 )
				ans[ qq[i].id ]= dd[f].s[ dd[f].len-1 ];
			else
				ans[ qq[i].id ]= dd[f].s[ dd[f].len-1 ]- dd[f].s[bas-1];
		}
		for(int i=1;i<=Q;i++) printf("%I64d\n",ans[i]);
	}
}


#pragma comment(linker, "/STACK:25600000")
#define _CRT_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef vector< vector<ll> > VVI;
typedef pair<ll, ll> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RREP(i, n) for(ll i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(ll i = x; i <= y; ++i)
#define RFOR(i, x, y) for(ll i = x; i >= y; --i)
#define SZ(a) (ll)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x,0,sizeof x);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define X first
#define Y second

const double pi=acos(-1.0);
const double eps = 1e-9;
const ll INF = 1000000000;

const int BORDER = 300;
struct request
{
    int a;
    int b;
    int num;
    ll res;
}r[102400];

bool cmp1(const request& a, const request& b)
{
    return a.b < b.b;
}

bool cmp2(const request& a, const request& b)
{
    return a.num < b.num;
}

int n, m;
int a[102400];
ll d[102400];

int main()
{
    cin >> n;
    FOR(i, 1, n)
        cin >> a[i];

    cin >> m;
    REP(i, m)
        cin >> r[i].a >> r[i].b;
    sort(r, r + m, cmp1);

    REP(i, m)
    {
        if (r[i].b > BORDER)
        {
            r[i].res = 0;
            for (int j = r[i].a; j <= n; j += r[i].b)
                r[i].res += a[j];
        }
        else
        {
            if (i == 0 || r[i].b != r[i-1].b)
            {
                memset(d, 0, sizeof d);
                RFOR(j, n, 1)
                {
                    d[j] = a[j];
                    if (j + r[i].b <= n)
                        d[j] += d[j + r[i].b];
                }
            }
            r[i].res = d[r[i].a];
        }
    }
    sort(r, r + m, cmp2);
    REP(i, m)
        cout << r[i].res << endl;
}


#pragma comment(linker, "/STACK:25600000")
#define _CRT_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef vector< vector<ll> > VVI;
typedef pair<ll, ll> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RREP(i, n) for(ll i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(ll i = x; i <= y; ++i)
#define RFOR(i, x, y) for(ll i = x; i >= y; --i)
#define SZ(a) (ll)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x,0,sizeof x);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define X first
#define Y second

const double pi=acos(-1.0);
const double eps = 1e-9;
const ll INF = 1000000000;

const int BORDER = 300;
struct request
{
    int a;
    int b;
    int num;
    ll res;
}r[3 * 102400];

bool cmp1(const request& a, const request& b)
{
    return a.b < b.b;
}

bool cmp2(const request& a, const request& b)
{
    return a.num < b.num;
}

int n, m;
int a[3 * 102400];
ll d[3 * 102400];

int main()
{
    cin >> n;
    FOR(i, 1, n)
        cin >> a[i];

    cin >> m;
    REP(i, m)
    {
        cin >> r[i].a >> r[i].b;
        r[i].num = i;
    }
    sort(r, r + m, cmp1);

    REP(i, m)
    {
        if (r[i].b > BORDER)
        {
            r[i].res = 0;
            for (int j = r[i].a; j <= n; j += r[i].b)
                r[i].res += a[j];
        }
        else
        {
            if (i == 0 || r[i].b != r[i-1].b)
            {
                memset(d, 0, sizeof d);
                RFOR(j, n, 1)
                {
                    d[j] = a[j];
                    if (j + r[i].b <= n)
                        d[j] += d[j + r[i].b];
                }
            }
            r[i].res = d[r[i].a];
        }
    }
    sort(r, r + m, cmp2);
    REP(i, m)
        cout << r[i].res << endl;
}


#pragma comment(linker, "/STACK:25600000")
#define _CRT_NO_WARNINGS
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <set>
#include <cassert>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef vector< vector<ll> > VVI;
typedef pair<ll, ll> PII;
typedef vector<PII> VPII;

#define REP(i, n) for(ll i = 0; i < n; ++i)
#define RREP(i, n) for(ll i = n - 1; i >= 0; --i)
#define FOR(i, x, y) for(ll i = x; i <= y; ++i)
#define RFOR(i, x, y) for(ll i = x; i >= y; --i)
#define SZ(a) (ll)(a).size()
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define CLEAR(x) memset(x,0,sizeof x);
#define UNIQUE(c) SORT(c),(c).resize(unique(ALL(c))-(c).begin())
#define pb push_back
#define mp make_pair
#define sqr(x) (x)*(x)
#define X first
#define Y second

const double pi=acos(-1.0);
const double eps = 1e-9;
const ll INF = 1000000000;

const int BORDER = 300;
struct request
{
    int a;
    int b;
    int num;
    ll res;
}r[102400];

bool cmp1(const request& a, const request& b)
{
    return a.b < b.b;
}

bool cmp2(const request& a, const request& b)
{
    return a.num < b.num;
}

int n, m;
int a[102400];
ll d[102400];

int main()
{
    cin >> n;
    FOR(i, 1, n)
        cin >> a[i];

    cin >> m;
    REP(i, m)
    {
        cin >> r[i].a >> r[i].b;
        r[i].num = i;
    }
    sort(r, r + m, cmp1);

    REP(i, m)
    {
        if (r[i].b > BORDER)
        {
            r[i].res = 0;
            for (int j = r[i].a; j <= n; j += r[i].b)
                r[i].res += a[j];
        }
        else
        {
            if (i == 0 || r[i].b != r[i-1].b)
            {
                memset(d, 0, sizeof d);
                RFOR(j, n, 1)
                {
                    d[j] = a[j];
                    if (j + r[i].b <= n)
                        d[j] += d[j + r[i].b];
                }
            }
            r[i].res = d[r[i].a];
        }
    }
    sort(r, r + m, cmp2);
    REP(i, m)
        cout << r[i].res << endl;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

struct zapros
{
	ll a, b, pos;
};

bool my_f(zapros a, zapros b)
{
	return a.b < b.b ||(a.b == b.b && a.a < b.a);
}

ll n, m, a, b, i, j, ans, x, ms[300010], last, an[300010], pos;
vector<ll> w;
vector<zapros> z;
zapros zp;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;

	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		zp.a = a;
		zp.b = b;
		zp.pos = i;
		z.push_back(zp);
	}
	sort(z.begin(), z.end(), my_f);
	last = 0;
	for(i = 0; i < m; i++)
	{
		a = z[i].a;
		b = z[i].b;
		pos = z[i].pos;
		ans = 0;
		if(b < 500)
		{
			if(b != last)
			{
				for(i = j; j < min(b,n); j++)
				{
					ms[j] = w[j-1];
				}
				for(j = 0; j+b <= n; j++)
				{
					ms[j+b] = ms[j] + w[j+b-1];
				}
			}
			last = b;
			x = n - a;
			x /= b;
			ans = ms[a+x*b];
			if(a > b)
				ans -= ms[a-b];
		}
		else
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		an[pos] = ans;
	}

	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

struct zapros
{
	ll a, b, pos;
};

bool my_f(zapros a, zapros b)
{
	return a.b < b.b ||(a.b == b.b && a.a < b.a);
}

ll n, m, a, b, i, j, ans, x, ms[300010], last, an[300010], pos;
vector<ll> w;
vector<zapros> z;
zapros zp;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;

	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		zp.a = a;
		zp.b = b;
		zp.pos = i;
		z.push_back(zp);
	}
	sort(z.begin(), z.end(), my_f);
	last = 0;
	for(i = 0; i < m; i++)
	{
		a = z[i].a;
		b = z[i].b;
		pos = z[i].pos;
		ans = 0;
		if(b < 500)
		{
			if(b != last)
			{
				for(j = 1; j < min(b,n); j++)
				{
					ms[j] = w[j-1];
				}
				for(j = 0; j+b <= n; j++)
				{
					ms[j+b] = ms[j] + w[j+b-1];
				}
			}
			last = b;
			x = n - a;
			x /= b;
			ans = ms[a+x*b];
			if(a > b)
				ans -= ms[a-b];
		}
		else
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		an[pos] = ans;
	}

	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[300010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][1010];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 1000; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b > 1000)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b+1][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][1010];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 1000; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b > 1000)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

struct zapros
{
	ll a, b, pos;
};

bool my_f(zapros a, zapros b)
{
	return a.b < b.b ||(a.b == b.b && a.a < b.a);
}

ll n, m, a, b, i, j, ans, x, ms[300010], last, an[300010], pos;
vector<ll> w;
vector<zapros> z;
zapros zp;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;

	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		zp.a = a;
		zp.b = b;
		zp.pos = i;
		z.push_back(zp);
	}
	sort(z.begin(), z.end(), my_f);
	last = 0;
	for(i = 0; i < m; i++)
	{
		a = z[i].a;
		b = z[i].b;
		pos = z[i].pos;
		ans = 0;
		if(b < 500)
		{
			if(b != last)
			{
				for(j = 1; j < min(b,n); j++)
				{
					ms[j] = w[j-1];
				}
				for(j = 0; j+b <= n; j++)
				{
					ms[j+b] = ms[j] + w[j+b-1];
				}
			}
			last = b;
			x = n - a;
			x /= b;
			ans = ms[a+x*b];
			if(a > b)
				ans -= ms[a-b];
		}
		else
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		an[pos] = ans;
	}

	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[100010][1010];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 1000; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b > 1000)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b+1][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[30010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef int ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[30010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; j <= n; j += b)
				ans += w[j-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][510];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 500; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b >= 500)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#include <stdio.h>
#include <fstream>
#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <map>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <set>
#include <utility>

using namespace std;

typedef long long ll;
typedef long double ld;

ll min(ll a, ll b)
{
	if(a < b)
		return a;
	else
		return b;
}

ll n, m, a, b, i, j, ans, x, ms[10010][1010];
vector<ll> w, an;

int main()
{
#ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
#endif
	cin >> n;
	for(i = 0; i < n; i++)
	{
		cin >> x;
		w.push_back(x);
	}
	cin >> m;
	for(b = 1; b < 1000; b++)
	{
		for(i = 1; i < min(b,n); i++)
		{
			ms[i][b] = w[i-1];
		}
		for(i = 0; i+b <= n; i++)
		{
			ms[i+b][b] = ms[i][b] + w[i+b-1];
		}
	}
	for(i = 0; i < m; i++)
	{
		cin >> a >> b;
		ans = 0;
		if(b > 1000)
		{
			for(j = a; i < n; i += b)
				ans += w[i-1];
		}
		else
		{
			x = n - a;
			x /= b;
			ans = ms[a+x*b][b];
			if(a > b)
				ans -= ms[a-b+1][b];
		}
		an.push_back(ans);
	}
	for(i = 0; i < m; i++)
	{
		cout << an[i] << endl;;
	}

    return 0;
}


#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long li;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <li, li> pli;
typedef vector <int> vi;
typedef vector <li> vli;
#define mp make_pair
#define pb push_back
void solve ();
int main ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
	int t=1;
	while (t--)
		solve ();
	return 0;
}
//caution: is int really int?
//#define int li
struct question
{
	int a, b, id;
	question() {};
	question ( int A, int B, int Id ) { a=A; b=B; id=Id; }
	bool operator < ( question &w ) { return b<w.b || (b==w.b && (a%b)<(w.a%b)); }
};
int n, p, a[300500];
question Q[300500];
li pref[300500];
li ans[300500];
void solve ()
{
	scanf ("%d", &n);
	for (int i=0; i<n; i++)
		scanf ("%d", &a[i]);
	scanf ("%d", &p);
	int t=0;
	for ( int i=0; i<p; i++ )
	{
		int q, w;
		scanf ("%d%d", &q, &w);
		Q[t++]=question(q-1, w, i);
	}
	sort (Q, Q+p);
	for ( int i=0; i<p; i++ )
	{
		pi cur=mp( Q[i].a, Q[i].b );
		int now=cur.first%cur.second;
		memset (pref, 0, sizeof(pref));
		pref[now]=(li)a[now];
		for ( int j=now+cur.second; j<n; j+=cur.second )
			pref[j]=(li)pref[j-cur.second]+a[j];
		int end=((n-1-now)/cur.second)*cur.second+now;
		bool flag=true;
		while ( i<p && Q[i].b==cur.second && Q[i].a%cur.second==now )
		{
			if ( Q[i].a==now )
				ans[Q[i].id]=pref[end];
			else
				ans[Q[i].id]=pref[end]-pref[Q[i].a-cur.second];
			i++;
			if ( i==p )
			{
				flag=false;
				break;
			}
		}
		if (flag)
		i--;
	}
	for ( int i=0; i<p; i++ )
		printf ("%I64d\n", ans[i]);
}


#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long li;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <li, li> pli;
typedef vector <int> vi;
typedef vector <li> vli;
#define mp make_pair
#define pb push_back
void solve ();
int main ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
	int t=1;
	while (t--)
		solve ();
	return 0;
}
//caution: is int really int?
#define int li
int n, p, a[300500];
map < pli, vector < pli > > m;
int pref[300500];
int ans[300500];
void solve ()
{
	cin>>n;
	for (int i=0; i<n; i++)
		scanf ("%I64d", &a[i]);
	cin>>p;
	for ( int i=0; i<p; i++ )
	{
		int q, w;
		scanf ("%I64d%I64d", &q, &w);
		m[mp((q-1)%w, w)].pb(mp(q-1, i));
	}
	for ( map <pli, vector <pli> >::iterator i=m.begin(); i!=m.end(); i++ )
	{
		pli cur=i->first;
		vector <pli> now=i->second;
		//cout<<cur.first<<' '<<cur.second<<endl;
		memset (pref, 0, sizeof (pref));
		pref[cur.first]=a[cur.first];
		int t=cur.first;
		for ( int j=cur.first+cur.second; j<n; j+=cur.second )
		{
				pref[j]=pref[j-cur.second]+a[j];
				t+=cur.second;
		}
		for ( int j=0; j<now.size(); j++ )
		{
			if ( now[j].first==cur.first )
				ans[now[j].second]=pref[t];
			else
				ans[now[j].second]=pref[t]-pref[now[j].first-cur.second];
		}
	}
	for ( int i=0; i<p; i++ )
		printf ("%I64d\n", ans[i]);
}


#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long li;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <li, li> pli;
typedef vector <int> vi;
typedef vector <li> vli;
#define mp make_pair
#define pb push_back
void solve ();
int main ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
	int t=1;
	while (t--)
		solve ();
	return 0;
}
//caution: is int really int?
//#define int li
struct question
{
	int a, b, id;
	question() {};
	question ( int A, int B, int Id ) { a=A; b=B; id=Id; }
	bool operator < ( question &w ) { return b<w.b || (b==w.b && (a%b)<(w.a%b)); }
};
int n, p, a[300500];
question Q[300500];
li pref[300500];
li ans[300500];
void solve ()
{
	scanf ("%d", &n);
	for (int i=0; i<n; i++)
		scanf ("%d", &a[i]);
	scanf ("%d", &p);
	int t=0;
	for ( int i=0; i<p; i++ )
	{
		int q, w;
		scanf ("%d%d", &q, &w);
		Q[t++]=question(q-1, w, i);
	}
	sort (Q, Q+p);
	for ( int i=0; i<p; i++ )
	{
		pi cur=mp( Q[i].a, Q[i].b );
		int now=cur.first%cur.second;
		pref[now]=(li)a[now];
		for ( int j=now+cur.second; j<n; j+=cur.second )
			pref[j]=(li)pref[j-cur.second]+a[j];
		int end=((n-1-now)/cur.second)*cur.second+now;
		bool flag=true;
		while ( i<p && Q[i].b==cur.second && Q[i].a%cur.second==now )
		{
			if ( Q[i].a==now )
				ans[Q[i].id]=pref[end];
			else
				ans[Q[i].id]=pref[end]-pref[Q[i].a-cur.second];
			i++;
			if ( i==p )
			{
				flag=false;
				break;
			}
		}
		if (flag)
		i--;
	}
	for ( int i=0; i<p; i++ )
		printf ("%I64d\n", ans[i]);
}


#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long li;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <li, li> pli;
typedef vector <int> vi;
typedef vector <li> vli;
#define mp make_pair
#define pb push_back
void solve ();
int main ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
	int t=1;
	while (t--)
		solve ();
	return 0;
}
//caution: is int really int?
#define int li
struct question
{
	int a, b, id;
	question() {};
	question ( int A, int B, int Id ) { a=A; b=B; id=Id; }
	bool operator < ( question &w ) { return b<w.b || (b==w.b && (a%b)<(w.a%b)); }
};
int n, p, a[300500];
question Q[300500];
int pref[300500];
int ans[300500];
void solve ()
{
	cin>>n;
	for (int i=0; i<n; i++)
		scanf ("%I64d", &a[i]);
	cin>>p;
	int t=0;
	for ( int i=0; i<p; i++ )
	{
		int q, w;
		scanf ("%I64d%I64d", &q, &w);
		Q[t++]=question(q-1, w, i);
	}
	sort (Q, Q+p);
	for ( int i=0; i<p; i++ )
	{
		pi cur=mp( Q[i].a, Q[i].b );
		int now=cur.first%cur.second;
		memset (pref, 0, sizeof(pref));
		pref[now]=a[now];
		int end=now;
		for ( int j=now+cur.second; j<n; j+=cur.second )
		{
			pref[j]=pref[j-cur.second]+a[j];
			end+=cur.second;
		}
		bool flag=true;
		while ( i<p && Q[i].b==cur.second && Q[i].a%cur.second==now )
		{
			if ( Q[i].a==cur.first )
				ans[Q[i].id]=pref[end];
			else
				ans[Q[i].id]=pref[end]-pref[Q[i].a-cur.second];
			i++;
			if ( i==p )
			{
				flag=false;
				break;
			}
		}
		if (flag)
		i--;
	}
	for ( int i=0; i<p; i++ )
		printf ("%I64d\n", ans[i]);
}


#define CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <memory.h>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long li;
typedef long double ld;
typedef pair <int, int> pi;
typedef pair <li, li> pli;
typedef vector <int> vi;
typedef vector <li> vli;
#define mp make_pair
#define pb push_back
void solve ();
int main ()
{
#ifdef _DEBUG
	freopen ("in.txt", "r", stdin);
#endif
	int t=1;
	while (t--)
		solve ();
	return 0;
}
//caution: is int really int?
#define int li
struct question
{
	int a, b, id;
	question() {};
	question ( int A, int B, int Id ) { a=A; b=B; id=Id; }
	bool operator < ( question &w ) { return b<w.b || (b==w.b && (a%b)<(w.a%b)); }
};
int n, p, a[300500];
question Q[300500];
int pref[300500];
int ans[300500];
void solve ()
{
	cin>>n;
	for (int i=0; i<n; i++)
		scanf ("%I64d", &a[i]);
	cin>>p;
	int t=0;
	for ( int i=0; i<p; i++ )
	{
		int q, w;
		scanf ("%I64d%I64d", &q, &w);
		Q[t++]=question(q-1, w, i);
	}
	sort (Q, Q+p);
	for ( int i=0; i<p; i++ )
	{
		pi cur=mp( Q[i].a, Q[i].b );
		int now=cur.first%cur.second;
		memset (pref, 0, sizeof(pref));
		pref[now]=a[now];
		int end=now;
		for ( int j=now+cur.second; j<n; j+=cur.second )
		{
			pref[j]=pref[j-cur.second]+a[j];
			end+=cur.second;
		}
		bool flag=true;
		while ( i<p && Q[i].b==cur.second && Q[i].a%cur.second==now )
		{
			if ( Q[i].a==now )
				ans[Q[i].id]=pref[end];
			else
				ans[Q[i].id]=pref[end]-pref[Q[i].a-cur.second];
			i++;
			if ( i==p )
			{
				flag=false;
				break;
			}
		}
		if (flag)
		i--;
	}
	for ( int i=0; i<p; i++ )
		printf ("%I64d\n", ans[i]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
//#define pdd pair<double,double>
#define x first
#define y second
#define VP vector< pii >
const int maxN=300000;
const int D=1000;
ll sum[D][D];
int n,p,m;
int a[maxN];
ll ans[maxN];
struct T
{
	int len;
	int st;
	int num;
};
inline bool operator<(const T&a, const T&b)
{
	if (a.len<D && b.len<D)
		return a.st<b.st;
	else
		if (a.len<D)
			return 1;
		else
			 return 0;
}
T q[maxN];
int main()
{
	scanf("%d",&n);
	rp(i,n)
		scanf("%d",&a[i]);
	scanf("%d",&m);
	rp(i,m)
	{
		scanf("%d%d",&q[i].st,&q[i].len);
		q[i].st--;
		q[i].num=i;
	}
	sort(q,q+m);
	for(int i=0;i<n;i+=D)
	{
		for(int st=0;st<D;st++)
			for(int step=1;step<D;++step)
				sum[st][step]=0;

		int fn=min(n-1,i+D-1);
		for(int st=fn;st>=i;--st)
			for(int step=1;step<D;++step)
				if (st+step>fn)
						sum[st-i][step]=a[st];
					else
						sum[st-i][step]=a[st]+sum[st-i+step][step];

		for(int st=0;st<m && q[st].st<i+D && q[st].len<D; st++)
		{
			int fst;
			if (q[st].st<i)
			{
				if ((i-q[st].st)%q[st].len==0)
					fst=i;
				else
					fst=i+(q[st].len-(i-q[st].st)%q[st].len);
			}
			else
				fst=q[st].st;

			ans[q[st].num]+=sum[fst-i][q[st].len];
		}
	}
	for(int st=0;st<m;++st)
		if (q[st].len>=D)
			for(int pos=q[st].st;pos<n;pos+=q[st].len)
				ans[q[st].num]+=a[pos];
	rp(st,m)
		printf("%I64d\n",ans[st]);
}


#define _CRT_SECURE_NO_DEPRECATE
#include <ctime>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
#define pb push_back
#define inf 1000000000
#define L(s) (int)(s).size()
#define rp(i,n) for(int (i)=0;(i)<(n);++(i))
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define VI vector<int>
#define mp make_pair
#define pii pair<int,int>
//#define pdd pair<double,double>
#define x first
#define y second
#define VP vector< pii >
const int maxN=300000;
const int D=700;
ll sum[maxN];
int n,p,m;
int a[maxN];
ll ans[maxN];
struct T
{
	int len;
	int st;
	int num;
};
inline bool operator<(const T&a, const T&b)
{
	if (a.len<D && b.len<D)
		return a.len<b.len;
	else
		if (a.len<D)
			return 1;
		else
			return 0;
}
T q[maxN];
int main()
{
	scanf("%d",&n);
	rp(i,n)
		scanf("%d",&a[i]);
	scanf("%d",&m);
	rp(i,m)
	{
		scanf("%d%d",&q[i].st,&q[i].len);
		q[i].st--;
		q[i].num=i;
	}
	sort(q,q+m);
	int pos=0;
	for(int step=1;step<D;++step)
	{
		VI nums(0);
		while(pos<m && q[pos].len==step)
			nums.pb(pos++);

		if (L(nums))
		{
			C(sum);
			for(int i=n-1;i>=0;--i)
				if (i+step>=n)
					sum[i]=a[i];
				else
					sum[i]=a[i]+sum[i+step];
		}

		rp(que,L(nums))
		{
			int at=nums[que];
			ans[q[at].num]=sum[q[at].st];
		}
	}
	int tot=0;
	for(int st=0;st<m;++st)
		if (q[st].len>=D)
		{
			tot++;
			for(int pos=q[st].st;pos<n;pos+=q[st].len)
				ans[q[st].num]+=a[pos];
		}
	rp(st,m)
		printf("%I64d\n",ans[st]);
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=550;
int a[c];
ll pr[d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j) {
			pr[i][j]=0;
			for (k=j*d; k<=n && k<(j+1)*d; k+=i)
				pr[i][j]+=a[k];
			if (j<d-1) pr[i][j]+=pr[i][j+1];
		}
	}
	int ind;
	ll ans;
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind];
			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
//			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=550;
int a[c];
ll pr[d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j) {
			pr[i][j]=0;
			for (k=j*d; k<=n && k<(j+1)*d; k+=i)
				pr[i][j]+=a[k];
			if (j<d-1) pr[i][j]+=pr[i][j+1];
		}
	}
	int ind;
	ll ans;
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <map>
#include <iostream>
using namespace std;
const int c=300500;
typedef long long ll;
typedef pair<int,int> pii;
map<pii,ll> mp;
ll a[c];
int n,p;
ll f(int i, int j) {
	if (i+j>n) return a[i];
	pii s(i,j);
	if (!mp.count(s)) mp[s]=f(i,(j<<1))+f(i+j,(j<<1));
	return mp[s];
}
int main() {
	scanf("%d",&n);
	int i;
	int j,k;
	for (i=1; i<=n; ++i) cin >> a[i];
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		scanf("%d%d",&j,&k);
		cout << f(j,k) << '\n';
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
const int c=300500;
struct rec {
	int i,a,b;
};
bool operator < (const rec &a, const rec &b) {
	if (a.b!=b.b) return a.b<b.b;
	if (a.a%a.b!=b.a%b.b) return a.a%a.b<b.a%b.b;
	return a.a>b.a;
}
int n,p;
int a[c];
rec m[c];
ll ans[c];
int main() {
	scanf("%d",&n);
	int i,j;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		m[i].i=i;
		scanf("%d%d",&m[i].a,&m[i].b);
	}
	m[0].b=0;
	sort(m+1,m+p+1);
	bool q;
	for (i=1; i<=p; ++i) {
		if (m[i].b==m[i-1].b && m[i].a%m[i].b==m[i-1].a%m[i-1].b) q=1; else q=0;
		ans[m[i].i]=0;
		j=m[i].a;
		while (j<=n && !(q && j==m[i-1].a)) {
			ans[m[i].i]+=a[j];
			j+=m[i].b;
		}
		if (q) ans[m[i].i]+=ans[m[i-1].i];
	}
	for (i=1; i<=p; ++i) cout << ans[i] << '\n';
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300500;
const int d=30;
int a[c];
ll pr[d][c];
int n,p;
ll xa,xb;
int main() {
	scanf("%d",&n);
	int i,j;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=n; j>=1; --j) {
			if (j+i>n) pr[i][j]=a[j]; else pr[i][j]=a[j]+pr[i][j+i];
		}
	}
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) cout << pr[xb][xa] << '\n'; else {
			ll ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=201;
const int e=1500;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1) pr[i][j][t]+=pr[i][j+1][(t+e)%i];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1][(xa+(ind+1)*e)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=201;
const int e=1700;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1) pr[i][j][t]+=pr[i][j+1][k%i];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1][(xa-(ind+1)*e%xb+xb)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=201;
const int e=1700;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1) pr[i][j][t]+=pr[i][j+1][k-(j+1)*e];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1][(xa-(ind+1)*e%xb+xb)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=201;
const int e=1700;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1) pr[i][j][t]+=pr[i][j+1][k-(j+1)*e];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1][(xa-(ind+1)*e%xb+xb)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*e && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=301;
const int e=1000;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1) pr[i][j][t]+=pr[i][j+1][(t+e)%i];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1][(xa+(ind+1)*e)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=27;
int a[c];
ll pr[d][c];
int n,p;
ll xa,xb;
int main() {
	scanf("%d",&n);
	int i,j;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=n; j>=1; --j) {
			if (j+i>n) pr[i][j]=a[j]; else pr[i][j]=a[j]+pr[i][j+i];
		}
	}
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) cout << pr[xb][xa] << '\n'; else {
			ll ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=550;
int a[c];
ll pr[d][d]; // ��� b - ������ ������, ����� ����� ������ ��� n/d ��������
int n,p;
ll xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j) {
			pr[i][j]=0;
			for (k=j*d; k<=n && k<(j+1)*d; k+=i)
				pr[i][j]+=a[k];
			if (j<d-1) pr[i][j]+=pr[i][j+1];
		}
	}
	int ind;
	ll ans;
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/d;
			ans=pr[xb][ind+1];
			for (k=xa; k<(ind+1)*d && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=201;
const int e=1700;
int a[c];
ll pr[d][d][d];
int n,p;
int xa,xb;
int main() {
	scanf("%d",&n);
	int i,j,k,t;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=d-1; j>=0; --j)
			for (t=0; t<i; ++t) {
				pr[i][j][t]=0;
				for (k=j*e+t; k<=n && k<(j+1)*e; k+=i)
					pr[i][j][t]+=a[k];
				if (j<d-1 && k<=n) pr[i][j][t]+=pr[i][j+1][k-(j+1)*e];
		   	}
	}
	int ind;
	ll ans;
//	cerr << pr[2][0] << '\n';
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) {
			ind=xa/e;
			ans=pr[xb][ind+1][(xa-(ind+1)*e%xb+xb)%xb];
//			cerr << xa << ' ' << xb << ' ' << ind << ' ' << ans << '\n';
//			for (k=xa-xb; k>=ind*d; k-=xb) ans-=a[k];
			for (k=xa; k<(ind+1)*e && k<=n; k+=xb) ans+=a[k];
			cout << ans << '\n';
		} else {
			ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <cstdio>
#include <iostream>
using namespace std;
typedef long long ll;
const int c=300001;
const int d=26;
int a[c];
ll pr[d][c];
int n,p;
ll xa,xb;
int main() {
	scanf("%d",&n);
	int i,j;
	for (i=1; i<=n; ++i) scanf("%d",&a[i]);
	for (i=1; i<d; ++i) {
		for (j=n; j>=1; --j) {
			if (j+i>n) pr[i][j]=a[j]; else pr[i][j]=a[j]+pr[i][j+i];
		}
	}
	scanf("%d",&p);
	for (i=1; i<=p; ++i) {
		cin >> xa >> xb;
		if (xb<d) cout << pr[xb][xa] << '\n'; else {
			ll ans=0;
			for (j=xa; j<=n; j+=xb) ans+=a[j];
			cout << ans << '\n';
		}
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <sstream>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <stack>
#include <fstream>
#include <cassert>
#ifdef HOME_PC
#include <ctime>
#endif
using namespace std;

#pragma comment(linker,"/stack:16000000")
#pragma warning (disable : 4996)

#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
#define mset(A,x) memset((A),(x),sizeof(A))
#define FOR(i,start,N) for(int i=(start);i<(N);++i)
#define FORSZ(i,start,v) FOR(i,start,SZ(v))
#define REPSZ(i,v) FORSZ(i,0,v)
#define FORE(i,start,N) FOR(i,start,N+1)
#define make_unique(v) v.resize(unique(ALL(v))-v.begin())
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define adebug(A,N) FOR(i,0,N) cout<<#A<<"["<<i<<"] = "<<A[i]<<endl;
#define adebug2d(a,n,m) FOR(i,0,n) { FOR(j,0,m) { cout<<a[i][j]<<" ";} cout<<endl;}
#define vdebug(v) REPSZ(i,v) cout<<#v<<"["<<i<<"] = "<<v[i]<<endl;
#define selfx(x,f,a) x = f(x,a)
#define sqr(x) ((x)*(x))

typedef pair<int,int> pii;
typedef long long i64;
typedef vector<int> VI; typedef vector< vector<int> > VVI;
typedef vector<string> VS;

const int inf = 1<<25;
const double eps = 1e-9;

struct Query
{
    int a,b,id;
    Query(int a,int b,int id):a(a),b(b),id(id){}
    bool operator<(const Query& other) const { return pii(b,a) < pii(other.b,other.a);}
};

i64 ans[333333];
i64 f[333333];

int main()
{
#ifdef HOME_PC
    //freopen ("input.txt","r",stdin);
    //freopen ("in.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#else
    //freopen ("input.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#endif
    int n;
    int w[333333];
    mset(w,0);
    cin>>n;
    FOR(i,0,n)
        cin>>w[i];

    int q;
    cin>>q;
    vector<Query> queries;
    FOR(i,0,q)
    {
        int a,b;
        cin>>a>>b;
        --a;
        queries.push_back(Query(a,b,i));
    }
    sort(ALL(queries));

    const int BOUND = 2000;

    REPSZ(i,queries)
    {
        int a = queries[i].a;
        int b = queries[i].b;
        int id = queries[i].id;
        ans[id] = 0;
        if(b > BOUND)
        {
            for(int j = a; j < n; j += b)
                ans[id] += w[j];
        }
        else
        {
            if(i == 0 || b != queries[i-1].b)
            {
                // recalc
                FOR(i,0,b)
                    f[i] = w[i];
                FOR(i,0,n)
                    f[i+b] = w[i+b] + f[i];
            }
            //ans
            ans[id] = f[a + (n-a)/b * b] - f[a] + w[a];
        }
    }

    FOR(i,0,q)
        printf("%I64d\n",ans[i]);

#ifdef HOME_PC
    cerr<<endl<<"Execution time = "<<clock()<<" ms"<<endl;
#endif
    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <queue>
#include <sstream>
#include <numeric>
#include <functional>
#include <set>
#include <cmath>
#include <stack>
#include <fstream>
#include <cassert>
#ifdef HOME_PC
#include <ctime>
#endif
using namespace std;

#pragma comment(linker,"/stack:16000000")
#pragma warning (disable : 4996)

#define ALL(v) v.begin(),v.end()
#define SZ(v) (int)v.size()
#define mset(A,x) memset((A),(x),sizeof(A))
#define FOR(i,start,N) for(int i=(start);i<(N);++i)
#define FORSZ(i,start,v) FOR(i,start,SZ(v))
#define REPSZ(i,v) FORSZ(i,0,v)
#define FORE(i,start,N) FOR(i,start,N+1)
#define make_unique(v) v.resize(unique(ALL(v))-v.begin())
#define debug(x) cout<<#x<<" = "<<x<<endl;
#define adebug(A,N) FOR(i,0,N) cout<<#A<<"["<<i<<"] = "<<A[i]<<endl;
#define adebug2d(a,n,m) FOR(i,0,n) { FOR(j,0,m) { cout<<a[i][j]<<" ";} cout<<endl;}
#define vdebug(v) REPSZ(i,v) cout<<#v<<"["<<i<<"] = "<<v[i]<<endl;
#define selfx(x,f,a) x = f(x,a)
#define sqr(x) ((x)*(x))

typedef pair<int,int> pii;
typedef long long i64;
typedef vector<int> VI; typedef vector< vector<int> > VVI;
typedef vector<string> VS;

const int inf = 1<<25;
const double eps = 1e-9;

struct Query
{
    int a,b,id;
    Query(int a,int b,int id):a(a),b(b),id(id){}
    bool operator<(const Query& other) const { return pii(b,a) < pii(other.b,other.a);}
};

i64 ans[333333];
i64 f[333333];

int main()
{
#ifdef HOME_PC
    //freopen ("input.txt","r",stdin);
    //freopen ("in.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#else
    //freopen ("input.txt","r",stdin);
    //freopen ("output.txt","w",stdout);
#endif
    int n;
    int w[333333];
    mset(w,0);
    cin>>n;
    FOR(i,0,n)
        cin>>w[i];

    int q;
    cin>>q;
    vector<Query> queries;
    FOR(i,0,q)
    {
        int a,b;
        cin>>a>>b;
        --a;
        queries.push_back(Query(a,b,i));
    }
    sort(ALL(queries));

    const int BOUND = 512;

    REPSZ(i,queries)
    {
        int a = queries[i].a;
        int b = queries[i].b;
        int id = queries[i].id;
        ans[id] = 0;
        if(b > BOUND)
        {
            for(int j = a; j < n; j += b)
                ans[id] += w[j];
        }
        else
        {
            if(i == 0 || b != queries[i-1].b)
            {
                // recalc
                FOR(i,0,b)
                    f[i] = w[i];
                FOR(i,0,n)
                    f[i+b] = w[i+b] + f[i];
            }
            //ans
            ans[id] = f[a + (n-a)/b * b] - f[a] + w[a];
        }
    }

    FOR(i,0,q)
        printf("%I64d\n",ans[i]);

#ifdef HOME_PC
    cerr<<endl<<"Execution time = "<<clock()<<" ms"<<endl;
#endif
    return 0;
}