#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 = 1000;

    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;
}


#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <ctime>
#include <cmath>
#include <cassert>
#include <algorithm>

using namespace std;

typedef long double ldb;
typedef long long int64;

double const pi = 3.1415926535897932384626433832795;
int const inf = (int) 1e9;
int64 const inf64 = (int64) 2e18;

#define y1 qqqqqqq
#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 seta(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define pii pair < int, int >
#define all(a) (a).begin(), (a).end()
#define mp make_pair
#define fs first
#define sc second
#define sqr(x) ((int64) x) * (x)

const string name = "d";

const int NMAX = 300010;
const int k = 300;

int n, m, w[NMAX];
int64 answer[NMAX], get[NMAX];
pair <pii, int> q[NMAX];

void pre_calc(int zn)
{
	for (int i = n - 1; i >= 0; --i)
	{
		get[i] = w[i];
		if (i + zn < n) get[i] += get[i + zn];
	}
}

int64 calc(int a, int b)
{
	int64 res = 0;
	while (a < n)
	{
		res += w[a];
		a += b;
	}
	return res;
}

int main()
{
	//freopen((name + ".in").data(), "r", stdin);
	//freopen((name + ".out").data(), "w", stdout);

/*	cout << 300000 << endl;
	forn(i, 300000)
		cout << 1000000000 << " ";
	cout << endl;
	cout << 300000 << endl;
	forn(i, 300000)
		cout << 1 << " " << 1 << endl;
	return 0;*/

	cin >> n;
	forn(i, n)
		scanf("%d", &w[i]);

	cin >> m;
	forn(i, m)
	{
		scanf("%d%d", &q[i].fs.sc, &q[i].fs.fs);
		q[i].fs.sc--;
		q[i].sc = i;
	}
	sort(q, q + m);

	int now = 0;
	forn(i, k)
	{
		pre_calc(i + 1);
		while (now < m && q[now].fs.fs == i + 1)
		{
			answer[q[now].sc] = get[q[now].fs.sc];
			now++;
		}
	}
	while (now < m)
	{
		answer[q[now].sc] = calc(q[now].fs.sc, q[now].fs.fs);
		now++;
	}

	forn(i, m)
		printf("%I64d\n", answer[i]);
	//cerr << clock() << endl;

	return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <functional>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <stack>
#include <map>
#include <set>

#define rep(i,a,b) for (int i = a; i <= b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define int64 long long
#define mp make_pair

using namespace std;

#ifdef _DEBUG
    const int N = 300;
#else
    const int N = 3000000;
#endif

const int inf = 2e9;
const int s = 600;

int n, m, p[N];
int64 dp[N], ans[N];
vector <pair<int, int>> v[N];

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    rep(i,0,n-1) scanf("%d", &p[i]);
    scanf("%d", &m);
    rep(i,1,m)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        v[b].push_back(mp(a, i));
    }
    rep(i,1,n) sort(v[i].begin(), v[i].end());
    rep(i,1,n)
    {
        if (!v[i].size()) continue;
        if (i <= s)
        {
            int j = v[i].size() - 1;
            rep(k,0,i) dp[k] = 0;
            repd(k,n-1,0)
            {
                dp[k % i] += p[k];
                while (j >= 0 && v[i][j].first == k + 1)
                {
                    ans[v[i][j].second] = dp[k % i];
                    j--;
                }
            }
        }
        else
        {
            for (int j = 0; j < v[i].size(); j++)
            {
                int64 res = 0;
                int k = v[i][j].first - 1;
                while (k < n)
                {
                    res += p[k];
                    k += i;
                }
                ans[v[i][j].second] = res;
            }
        }
    }
    rep(i,1,m) printf("%I64d\n", ans[i]);
    return 0;
}


#include <iostream>
#include <vector>
#include <queue>
#include <fstream>
#include <functional>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cstring>
#include <stack>
#include <map>
#include <set>

#define rep(i,a,b) for (int i = a; i <= b; i++)
#define repd(i,a,b) for (int i = a; i >= b; i--)
#define int64 long long
#define mp make_pair

using namespace std;

#ifdef _DEBUG
    const int N = 300;
#else
    const int N = 500000;
#endif

const int inf = 2e9;
const int s = 600;

int n, m, p[N];
int64 dp[N], ans[N];
vector <pair<int, int>> v[N];

int main()
{
#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    scanf("%d", &n);
    rep(i,0,n-1) scanf("%d", &p[i]);
    scanf("%d", &m);
    rep(i,1,m)
    {
        int a, b;
        scanf("%d%d", &a, &b);
        v[b].push_back(mp(a, i));
    }
    rep(i,1,n) sort(v[i].begin(), v[i].end());
    rep(i,1,n)
    {
        if (!v[i].size()) continue;
        if (i <= s)
        {
            int j = v[i].size() - 1;
            rep(k,0,i) dp[k] = 0;
            repd(k,n-1,0)
            {
                dp[k % i] += p[k];
                while (j >= 0 && v[i][j].first == k + 1)
                {
                    ans[v[i][j].second] = dp[k % i];
                    j--;
                }
            }
        }
        else
        {
            for (int j = 0; j < v[i].size(); j++)
            {
                int64 res = 0;
                int k = v[i][j].first - 1;
                while (k < n)
                {
                    res += p[k];
                    k += i;
                }
                ans[v[i][j].second] = res;
            }
        }
    }
    rep(i,1,m) printf("%I64d\n", ans[i]);
    return 0;
}


#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
#define P pair<int, int>
#define LL long long
P q[300000];
LL w[300000];
bool comp(int a, int b){
    if(q[a] < q[b])
        return true;
    return false;
}
int a[300000];
LL ans[300000];
LL b[300000];
int main(){
    int n, p;
    cin >> n;
    for(int i = 0; i < n; i++)
        scanf("%I64d", &w[i]);
    cin >> p;
    for(int i = 0; i < p; i++){
        a[i] = i;
        scanf("%d%d", &q[i].second, &q[i].first);
    }
    sort(a, a + p, comp);
    for(int i = 0; i < p; i++){
        int y = q[a[i]].first, x = q[a[i]].second - 1;
        if(y >= n / y)
            b[x] = 0;
        else if(!i || y != q[a[i - 1]].first)
            memset(b, 0, sizeof b);
        if(b[x]){
            ans[a[i]] = b[x];
        }
        else{
            int k = (n - x) / y;
            if((n - x) % y == 0)
                k--;
            int x1 = x + k * y;
            b[x1] = w[x1];
            x1 -= y;
            while(x1 >= 0){
                b[x1] = b[x1 + y] + w[x1];
                x1 -= y;
            }

            ans[a[i]] = b[x];
        }
    }
    for(int i = 0; i < p; i++)
        printf("%I64d\n", ans[i]);
    return 0;
}


#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
using namespace std;
#define P pair<int, int>
#define LL long long
P q[300000];
LL w[300000];
bool comp(int a, int b){
    if(q[a] < q[b])
        return true;
    return false;
}
int a[300000];
LL ans[300000];
LL b[300000];
int main(){
    int n, p;
    cin >> n;
    for(int i = 0; i < n; i++)
        scanf("%I64d", &w[i]);
    cin >> p;
    for(int i = 0; i < p; i++){
        a[i] = i;
        scanf("%d%d", &q[i].second, &q[i].first);
    }
    sort(a, a + p, comp);
    for(int i = 0; i < p; i++){
        if(!i || q[a[i]].first != q[a[i - 1]].first)
            memset(b, 0, sizeof b);
        int y = q[a[i]].first, x = q[a[i]].second - 1;
        if(b[x]){
            ans[a[i]] = b[x];
        }
        else{
            int k = (n - x) / y;
            if((n - x) % y == 0)
                k--;
            int x1 = x + k * y;
            b[x1] = w[x1];
            x1 -= y;
            while(x1 >= 0){
                b[x1] = b[x1 + y] + w[x1];
                x1 -= y;
            }

            ans[a[i]] = b[x];
        }
    }
    for(int i = 0; i < p; i++)
        printf("%I64d\n", ans[i]);
    return 0;
}


#include <iostream>
#include <string>
#include <string.h>
#include <cstring>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <bitset>
#include <queue>

using namespace std;

vector < int > c[560];
int n, p;
int w[310000];
int a[310000], b[310000];
long long res[310000];
long long s[310000];

int main()
{
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++)
		scanf("%d", &w[i]);
	scanf("%d", &p);
	for (int i = 1; i <= p; i ++)
	{
		scanf("%d%d", &a[i], &b[i]);
		if (b[i] <= 550) c[b[i]].push_back(i); else
		{
			long long cur = 0;
			int A = a[i], B = b[i];
			for (int j = A; j <= n; j += B)
				cur += (long long)(w[j]);
			res[i] = cur;
		}
	}

	for (int i = 1; i <= 550; i ++)
		if (c[i].size() != 0)
		{
			for (int j = 1; j <= n; j ++)
				if (j <= i) s[j] = w[j]; else s[j] = s[j - i] + (long long)(w[j]);

			for (int j = 0; j < c[i].size(); j ++)
			{
				int A = a[c[i][j]];
				int k = (n - A) / i;
				long long s1 = s[A + k * i];
				long long s2 = A - i > 0 ? s[A - i] : 0;
				res[c[i][j]] = s1 - s2;
			}
		}

	for (int i = 1; i <= p; i ++)
		printf("%I64d\n", res[i]);
	return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <memory>
using namespace std;
#define pb push_back
#define INF 1000000000
#define L(s) (int)((s).end()-(s).begin())
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
//#define x first
//#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pi 3.1415926535897932384626433832795028841971
//#define tt (ll+rr)/2
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define rnd() ((rand() << 16) ^ rand())

const int c = 543;

void gen()
{
	freopen("input.txt","wt",stdout);

	int N = 300000, P = 300000;
	printf("%d\n", N);
	rept(i, N)
		printf("%d ", abs(rnd()));
	printf("%d\n", P);
	rept(i, P)
		printf("%d %d\n", rand() % N + 1, rand() % N + 1);
}

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

	int n;
	scanf("%d", &n);
	VI w(n);
	rept(i, n)
		scanf("%d", &w[i]);

	vector<pii> q;
	map<pii, ll> cache;
	int p;
	scanf("%d", &p);
	rept(i, p)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		q.pb(mp(a, b));
		if (b >= c)
		{
			ll res = 0;
			for (int i = a; i < n; i += b)
				res += w[i];
			cache[mp(a, b)] = res;
		}
	}
	vector<vector<int> > g(c);
	rept(i, L(q))
		if (q[i].second < c)
			g[q[i].second].pb(q[i].first);

	vector<ll> csum(n);

	rep(i, c - 1) if (L(g[i]) > 0)
	{
		int base = i;
		rept(j, n)
		{
			csum[j] = 0;
			if (j >= base)
				csum[j] = csum[(j / base - 1) * base + j % base];
			csum[j] += w[j];
		}
		rept(j, L(g[i]))
		{
			int a = g[i][j];
			int b = base;
			int rem = a % b;
			int last = n / b * b + rem;
			if (last >= n) last -= b;
			if (last < 0 || last >= n)
				continue;
			ll tot = csum[last];
			if (a >= b)
				tot -= csum[a - b];
			cache[mp(a, b)] = tot;
		}
	}

	rept(i, L(q))
		printf("%I64d\n",cache[q[i]]);

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <memory>
using namespace std;
#define pb push_back
#define INF 1000000000
#define L(s) (int)((s).end()-(s).begin())
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
//#define x first
//#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pi 3.1415926535897932384626433832795028841971
//#define tt (ll+rr)/2
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define rnd() ((rand() << 16) ^ rand())

const int c = 543;

void gen()
{
	freopen("input.txt","wt",stdout);

	int N = 300000, P = 300000;
	printf("%d\n", N);
	rept(i, N)
		printf("%d ", abs(rnd()));
	printf("%d\n", P);
	rept(i, P)
		printf("%d %d\n", i + 1, i + 1);
}

ll csum[333333];

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

	int n;
	scanf("%d", &n);
	VI w(n);
	rept(i, n)
		scanf("%d", &w[i]);

	vector<pii> q;
	map<pii, ll> cache;
	int p;
	scanf("%d", &p);
	rept(i, p)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		q.pb(mp(a, b));
		if (b >= c)
		{
			ll res = 0;
			for (int i = a; i < n; i += b)
				res += w[i];
			cache[mp(a, b)] = res;
		}
	}
	vector<vector<int> > g(c);
	rept(i, L(q))
		if (q[i].second < c)
			g[q[i].second].pb(q[i].first);

	rep(i, c - 1) if (L(g[i]) > 0)
	{
		int base = i;
		C(csum);
		rept(j, n)
		{
			if (j >= base)
				csum[j] = csum[(j / base - 1) * base + j % base];
			csum[j] += w[j];
		}
		rept(j, L(g[i]))
		{
			int a = g[i][j];
			int b = base;
			int rem = a % b;
			int last = n / b * b + rem;
			if (last >= n) last -= b;
			if (last < 0 || last >= n)
				continue;
			ll tot = csum[last];
			if (a >= b)
				tot -= csum[a - b];
			cache[mp(a, b)] = tot;
		}
	}
	//cout << clock() << endl; return 0;
	rept(i, L(q))
		printf("%I64d\n",cache[q[i]]);

    return 0;
}


#define _CRT_SECURE_NO_DEPRECATE
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <iostream>
#include <cmath>
#include <sstream>
#include <map>
#include <set>
#include <stack>
#include <cstring>
#include <ctime>
#include <cstdio>
#include <memory>
using namespace std;
#define pb push_back
#define INF 1000000000
#define L(s) (int)((s).end()-(s).begin())
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORD(i,a,b) for(int i = (a); i >= (b); i--)
#define rep(i,n) FOR(i,1,(n))
#define rept(i,n) FOR(i,0,(n)-1)
#define C(a) memset((a),0,sizeof(a))
#define ll long long
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define VI vector<int>
#define ppb pop_back
#define mp make_pair
#define pii pair<int,int>
#define pdd pair<double,double>
//#define x first
//#define y second
#define sqr(a) (a)*(a)
#define D(a,b) sqrt(((a).x-(b).x)*((a).x-(b).x)+((a).y-(b).y)*((a).y-(b).y))
#define pi 3.1415926535897932384626433832795028841971
//#define tt (ll+rr)/2
#define UN(v) sort((v).begin(),(v).end()),v.erase(unique(v.begin(),v.end()),v.end())
#define rnd() ((rand() << 16) ^ rand())

const int c = 543;

void gen()
{
	freopen("input.txt","wt",stdout);

	int N = 300000, P = 300000;
	printf("%d\n", N);
	rept(i, N)
		printf("%d ", abs(rnd()));
	printf("%d\n", P);
	rept(i, P)
		printf("%d %d\n", rand() % N + 1, rand() % N + 1);
}

int csum[333333];

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

	int n;
	scanf("%d", &n);
	VI w(n);
	rept(i, n)
		scanf("%d", &w[i]);

	vector<pii> q;
	map<pii, ll> cache;
	int p;
	scanf("%d", &p);
	rept(i, p)
	{
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		q.pb(mp(a, b));
		if (b >= c)
		{
			ll res = 0;
			for (int i = a; i < n; i += b)
				res += w[i];
			cache[mp(a, b)] = res;
		}
	}
	vector<vector<int> > g(c);
	rept(i, L(q))
		if (q[i].second < c)
			g[q[i].second].pb(q[i].first);

	rep(i, c - 1) if (L(g[i]) > 0)
	{
		int base = i;
		C(csum);
		rept(j, n)
		{
			if (j >= base)
				csum[j] = csum[(j / base - 1) * base + j % base];
			csum[j] += w[j];
		}
		rept(j, L(g[i]))
		{
			int a = g[i][j];
			int b = base;
			int rem = a % b;
			int last = n / b * b + rem;
			if (last >= n) last -= b;
			if (last < 0 || last >= n)
				continue;
			ll tot = csum[last];
			if (a >= b)
				tot -= csum[a - b];
			cache[mp(a, b)] = tot;
		}
	}
	//cout << clock() << endl; return 0;
	rept(i, L(q))
		printf("%I64d\n",cache[q[i]]);

    return 0;
}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define print(expr) cout<<(#expr)<<" : "<<(expr)<<endl

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;
typedef pair<int,int> pii;

#ifdef ONLINE_JUDGE
const int _maxio=1000000;
char _buf[_maxio], *_s=_buf+_maxio;
inline char _getc(void){if(_s>=_buf+_maxio){fread(_buf,sizeof(char),_maxio,stdin);_s=_buf;}return *(_s++);}
inline int ni(void){char _t=_getc();int _n=1,_res=0;while(_t!='-' && !isdigit(_t)) _t=_getc();if(_t=='-') { _n=-1; _t=_getc();}	while(isdigit(_t)) { _res = 10*_res + (_t&15); _t=_getc();}return _res*_n;}
#else
inline int ni(void) { int _t; scanf("%d",&_t); return _t; }
#endif
const int maxn=300050;

pii q[maxn]={};
VI part[1000];
int buf[maxn]={};
int n,p;
int64 ans[maxn]={};

inline int updiv(int a,int b)
{
	return a%b==0  ? (a/b) : (a/b)+1;
}

int main(void)
{
	n=ni();
	rep(i,n) buf[i]=ni();
	p=ni();
	rep(i,p) { q[i].first=ni()-1; q[i].second=ni();}
	int maxq=0;
	rep(i,p)
	{
		if(q[i].second*q[i].second < n) { part[q[i].second].PB(i); maxq=max(q[i].second,maxq);}
		else
		{
			int64 &res=ans[i];
			res=0;
			int a=q[i].first, b=q[i].second;
			while(a<n) { res += buf[a]; a+=b;}
		}
	}
	REP(b,maxq) if(!part[b].empty())
	{
		vector< vector<int64> > vec;
		vec.resize(b);
		rep(i,b)
		{
			vec[i].resize(updiv(n-i,b));
			rep(j,vec[i].size())
			{
				if(!j) vec[i][j]=buf[j*b+i];
				else vec[i][j]=vec[i][j-1]+buf[j*b+i];
			}
		}
		rep(i,part[b].size())
		{
			int no=part[b][i];
			int a=q[no].first;
			int r=a%b,d=a/b;
			if(d==0) ans[no]=vec[r].back();
			else ans[no]=vec[r].back()-vec[r][d-1];
		}
	}
	rep(i,p) printf("%I64d\n",ans[i]);
	return 0;

}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define print(expr) cout<<(#expr)<<" : "<<(expr)<<endl

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;
typedef pair<int,int> pii;

#ifdef ONLINE_JUDGE
const int _maxio=1000000;
char _buf[_maxio], *_s=_buf+_maxio;
inline char _getc(void){if(_s>=_buf+_maxio){fread(_buf,sizeof(char),_maxio,stdin);_s=_buf;}return *(_s++);}
inline int ni(void){char _t=_getc();int _n=1,_res=0;while(_t!='-' && !isdigit(_t)) _t=_getc();if(_t=='-') { _n=-1; _t=_getc();}	while(isdigit(_t)) { _res = 10*_res + (_t&15); _t=_getc();}return _res*_n;}
#else
inline int ni(void) { int _t; scanf("%d",&_t); return _t; }
#endif
const int maxn=300050;

pii q[maxn]={};
VI part[600];
int buf[maxn]={};
int n,p;
int64 ans[maxn]={};

inline int updiv(int a,int b)
{
	return a%b==0  ? (a/b) : (a/b)+1;
}

int main(void)
{
	n=ni();
	rep(i,n) buf[i]=ni();
	p=ni();
	rep(i,p) { q[i].first=ni()-1; q[i].second=ni();}
	int maxq=0;
	rep(i,p)
	{
		if((int64)q[i].second*q[i].second < n) { part[q[i].second].PB(i); maxq=max(q[i].second,maxq);}
		else
		{
			int64 &res=ans[i];
			res=0;
			int a=q[i].first, b=q[i].second;
			while(a<n) { res += buf[a]; a+=b;}
		}
	}
	REP(b,maxq) if(!part[b].empty())
	{
		vector< vector<int64> > vec;
		vec.resize(b);
		rep(i,b)
		{
			vec[i].resize(updiv(n-i,b));
			rep(j,vec[i].size())
			{
				if(!j) vec[i][j]=buf[j*b+i];
				else vec[i][j]=vec[i][j-1]+buf[j*b+i];
			}
		}
		rep(i,part[b].size())
		{
			int no=part[b][i];
			int a=q[no].first;
			int r=a%b,d=a/b;
			if(d==0) ans[no]=vec[r].back();
			else ans[no]=vec[r].back()-vec[r][d-1];
		}
	}
	rep(i,p) printf("%I64d\n",ans[i]);
	return 0;

}


#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
using namespace std;

#define PB push_back
#define MP make_pair

#define rep(i,n) for(int i=0;i<(n);++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define FOR(i,l,h) for(int i=(l);i<=(h);++i)
#define FORD(i,h,l) for(int i=(h);i>=(l);--i)
#define print(expr) cout<<(#expr)<<" : "<<(expr)<<endl

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef long long int64;
typedef pair<int,int> pii;

#ifdef ONLINE_JUDGE
const int _maxio=1000000;
char _buf[_maxio], *_s=_buf+_maxio;
inline char _getc(void){if(_s>=_buf+_maxio){fread(_buf,sizeof(char),_maxio,stdin);_s=_buf;}return *(_s++);}
inline int ni(void){char _t=_getc();int _n=1,_res=0;while(_t!='-' && !isdigit(_t)) _t=_getc();if(_t=='-') { _n=-1; _t=_getc();}	while(isdigit(_t)) { _res = 10*_res + (_t&15); _t=_getc();}return _res*_n;}
#else
inline int ni(void) { int _t; scanf("%d",&_t); return _t; }
#endif
const int maxn=300050;

pii q[maxn]={};
VI part[600];
int buf[maxn]={};
int n,p;
int64 ans[maxn]={};

inline int updiv(int a,int b)
{
	return a%b==0  ? (a/b) : (a/b)+1;
}

int main(void)
{
	n=ni();
	rep(i,n) buf[i]=ni();
	p=ni();
	rep(i,p) { q[i].first=ni()-1; q[i].second=ni();}
	int maxq=0;
	rep(i,p)
	{
		if(q[i].second*q[i].second < n) { part[q[i].second].PB(i); maxq=max(q[i].second,maxq);}
		else
		{
			int64 &res=ans[i];
			res=0;
			int a=q[i].first, b=q[i].second;
			while(a<n) { res += buf[a]; a+=b;}
		}
	}
	REP(b,maxq) if(!part[b].empty())
	{
		vector< vector<int64> > vec;
		vec.resize(b);
		rep(i,b)
		{
			vec[i].resize(updiv(n-i,b));
			rep(j,vec[i].size())
			{
				if(!j) vec[i][j]=buf[j*b+i];
				else vec[i][j]=vec[i][j-1]+buf[j*b+i];
			}
		}
		rep(i,part[b].size())
		{
			int no=part[b][i];
			int a=q[no].first;
			int r=a%b,d=a/b;
			if(d==0) ans[no]=vec[r].back();
			else ans[no]=vec[r].back()-vec[r][d-1];
		}
	}
	rep(i,p) printf("%I64d\n",ans[i]);
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <list>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <complex>
#include <stack>
#include <queue>
#include <ctime>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef complex <double> pt;
typedef complex <ll> pti;

int main() {
	//ifstream fin("input.txt", ios::in);
	//ofstream fout("output.txt", ios::out);
	//FILE *fpin=fopen("input.txt", "r");
	//FILE *fpout=fopen("output.txt", "w");
	istream &fin=cin;
	ostream &fout=cout;
	FILE *fpin=stdin;
	FILE *fpout=stdout;

	int n;
	fin >> n;
	int w[300010];
	for(int i=0; i<n; i++) fin >> w[i];

	int p;
	fin >> p;
	vector <vector <ll> > ab(p);
	for(int i=0; i<p; i++) {
		ab[i].resize(4);
		fin >> ab[i][1] >> ab[i][0];
		ab[i][1]--;
		ab[i][2]=i;
	}
	sort(ab.begin(), ab.end());

	ll dp[300010];
	int rtn=(int)sqrt((double)n);
	int pb=-1;
	for(int i=0; i<p; i++) {
		int a=ab[i][1], b=ab[i][0];
		if(b!=pb && b<=rtn) {
			for(int j=0; j<n; j++) {
				if(j-b<0) dp[j]=w[j];
				else dp[j]=dp[j-b]+w[j];
			}
		}
		pb=b;
		ll res=0;
		if(b<=rtn) {
			int num=(n-(a-b+1))/b;
			int last=(a-b)+b*num;
			res=dp[last]-dp[a]+w[a];
		} else {
			for(int j=a; j<n; j+=b) {
				res+=w[j];
			}
		}
		ab[i][3]=res;
		swap(ab[i][0], ab[i][2]);
	}

	sort(ab.begin(), ab.end());
	for(int i=0; i<p; i++) {
		fout << ab[i][3] << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <list>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <numeric>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <iterator>
#include <complex>
#include <stack>
#include <queue>
#include <ctime>
using namespace std;
static const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef complex <double> pt;
typedef complex <ll> pti;

int main() {
	//ifstream fin("input.txt", ios::in);
	//ofstream fout("output.txt", ios::out);
	//FILE *fpin=fopen("input.txt", "r");
	//FILE *fpout=fopen("output.txt", "w");
	istream &fin=cin;
	ostream &fout=cout;
	FILE *fpin=stdin;
	FILE *fpout=stdout;

	int n;
	fin >> n;
	int w[300010];
	for(int i=0; i<n; i++) fin >> w[i];

	ll dp[1000][1000];
	int rtn=(int)sqrt((double)n);
	for(int i=1; i<=rtn; i++) {
		for(int j=0; j<n; j++) {
			if(j-i<0) dp[i][j]=w[j];
			else dp[i][j]=dp[i][j-i]+w[j];
		}
	}

	int p;
	fin >> p;
	for(int i=0; i<p; i++) {
		int a, b;
		fin >> a >> b;
		a--; b;
		if(b<=rtn) {
			int num=(n-(a-b+1))/b;
			int last=(a-b)+b*num;
			ll res=dp[b][last]-dp[b][a]+w[a];
			fout << res << endl;
		} else {
			ll res=0;
			for(int j=a; j<n; j+=b) {
				res+=w[j];
			}
			fout << res << endl;
		}
	}
}


#include <cstdio>
#include <algorithm>
using namespace std;

int w[300000];

int a[300000];
int b[300000];
int qid[300000];
long long qans[300000];
long long ans[300000];
int N,Q;

bool cmp(int x,int y)
{
	return b[x]<b[y];
}

void calc(int bb)
{
	for(int i=N-1;i>=0;i--)
	{
		ans[i] = w[i];
		if((i+bb)<N)
			ans[i] += ans[i+bb];
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d",&w[i]);
	scanf("%d",&Q);
	for(int i=0;i<Q;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
		a[i]--;
		qid[i] = i;
	}
	sort(qid,qid+Q,cmp);
	int pre = b[qid[0]];
	int bb;
	long long tot;
	for(int i=0;i<Q;i++)
	{
		bb = b[qid[i]];
		if((bb*bb <= N)&&((i==0)||(bb!=b[qid[i-1]])))
			calc(bb);
		if(bb*bb > N)
		{
			tot = 0;
			for(int j=a[qid[i]];j<N;j+=bb)
				tot += w[j];
			qans[qid[i]] = tot;
		}
		else
			qans[qid[i]] = ans[a[qid[i]]];
	}
	for(int i=0;i<Q;i++)
		printf("%I64d\n",qans[i]);
	return 0;
}


#include <cstdio>
#include <algorithm>
using namespace std;

int w[300000];

int a[300000];
int b[300000];
int qid[300000];
long long qans[300000];
long long ans[300000];
int N,Q;

bool cmp(int x,int y)
{
	return b[x]<b[y];
}

void calc(int bb)
{
	for(int i=N-1;i>=0;i--)
	{
		ans[i] = w[i];
		if((i+bb)<N)
			ans[i] += ans[i+bb];
	}
}

int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)
		scanf("%d",&w[i]);
	scanf("%d",&Q);
	for(int i=0;i<Q;i++)
	{
		scanf("%d %d",&a[i],&b[i]);
		a[i]--;
		qid[i] = i;
	}
	sort(qid,qid+Q,cmp);
	int pre = b[qid[0]];
	long long bb;
	long long tot;
	for(int i=0;i<Q;i++)
	{
		bb = b[qid[i]];
		if((bb*bb <= N)&&((i==0)||(bb!=b[qid[i-1]])))
			calc(bb);
		if(bb*bb > N)
		{
			tot = 0;
			for(int j=a[qid[i]];j<N;j+=bb)
				tot += w[j];
			qans[qid[i]] = tot;
		}
		else
			qans[qid[i]] = ans[a[qid[i]]];
	}
	for(int i=0;i<Q;i++)
		printf("%I64d\n",qans[i]);
	return 0;
}


#include <fstream>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
#include <hash_map>
#include <memory.h>
#include <queue>
#include <list>

using namespace std;
using namespace stdext;

#ifdef ONLINE_JUDGE
#include <iostream>
#else
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif

#define int long long

struct query
{
	int a, b, index;
	bool operator < (query &q)
	{
		return a < q.a || a == q.a && b < q.b;
	}
};

int n, p, cnt;
int w[400000], sum[400000];

void findSum(query &q)
{
	cnt = 0;
	for(int i = q.a%q.b; i < n; i += q.b)
	{
		sum[cnt] = w[i];
		cnt++;
	}
	for(int i = cnt-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

query v[400000];

__int32 main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> w[i];
	cin >> p;
	for(int i = 0; i < p; i++)
	{
		cin >> v[i].a >> v[i].b;
		v[i].a--;
		v[i].index = i;
	}
	vector<int> ans(p);
	sort(v,v+p);
	for(int i = 0; i < p; i++)
	{
		if(i == 0 || v[i].a%v[i].b != v[i-1].a%v[i].b || v[i].b != v[i-1].b)
			findSum(v[i]);
		ans[v[i].index] = sum[v[i].a/v[i].b];
	}
	for(int i = 0; i < p; i++)
		cout << ans[i] << endl;
}


#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
#include <hash_map>
#include <memory.h>
#include <queue>
#include <list>

using namespace std;
using namespace stdext;

#ifdef ONLINE_JUDGE
#include <iostream>
#else
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif

#define int long long

struct query
{
	int a, b, index;
	bool operator < (query &q)
	{
		return a < q.a || a == q.a && b < q.b;
	}
};

int n, p;
vector<int> w, sum;

map<pair<int,int>, vector<int> > ma;

void findSum(query &q)
{
	sum.clear();
	for(int i = q.a%q.b; i < n; i += q.b)
		sum.push_back(w[i]);
	for(int i = (int)sum.size()-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

void calc(int a, int b, vector<int> &sum)
{
	sum.reserve(n/b);
	for(int i = a; i < n; i += b)
		sum.push_back(w[i]);
	for(int i = (int)sum.size()-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

vector<query> v;

__int32 main()
{
	cin >> n;
	w.resize(n);
	for(int i = 0; i < n; i++)
		cin >> w[i];
	cin >> p;
	v.resize(p);
	for(int i = 0; i < p; i++)
	{
		cin >> v[i].a >> v[i].b;
		v[i].a--;
		v[i].index = i;
	}
	vector<int> ans(p);
	sort(v.begin(),v.end());
	for(int i = 0; i < p; i++)
	{
		if(i == 0 || v[i].a != v[i-1].a || v[i].b != v[i-1].b)
			findSum(v[i]);
		ans[v[i].index] = sum[v[i].a/v[i].b];
	}
	for(int i = 0; i < p; i++)
		cout << ans[i] << endl;
}


#include <fstream>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
#include <hash_map>
#include <memory.h>
#include <queue>
#include <list>

using namespace std;
using namespace stdext;

#ifdef ONLINE_JUDGE
#include <iostream>
#else
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif

#define int long long

struct query
{
	int a, b, index;
	bool operator < (query &q)
	{
		return a%b < q.a%q.b || a%b == q.a%q.b && b < q.b;
	}
};

int n, p, cnt;
int w[400000], sum[400000];

int aaa = 0;

void findSum(query &q)
{
	aaa++;
	cnt = 0;
	for(int i = q.a%q.b; i < n; i += q.b)
	{
		sum[cnt] = w[i];
		cnt++;
	}
	for(int i = cnt-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

query v[400000];

__int32 main()
{
	/*int n = 300000;
	cout << n << ' ' << n << endl;
	int a = 1, b = 1;
	for(int i = 0; i < n ;i++)
	{
		cout << a << ' '<<  b << endl;
		if(a == b)
		{
			b++;
			a = 1;
		}
		else
			a++;
	}
	return 0;/**/
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> w[i];
	cin >> p;
	for(int i = 0; i < p; i++)
	{
		cin >> v[i].a >> v[i].b;
		v[i].a--;
		v[i].index = i;
	}
	vector<int> ans(p);
	sort(v,v+p);
	for(int i = 0; i < p; i++)
	{
		if(i == 0 || v[i].a%v[i].b != v[i-1].a%v[i].b || v[i].b != v[i-1].b)
			findSum(v[i]);
		ans[v[i].index] = sum[v[i].a/v[i].b];
	}
	for(int i = 0; i < p; i++)
		cout << ans[i] << endl;
	//cout << aaa << endl;
}


#include <fstream>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
#include <hash_map>
#include <memory.h>
#include <queue>
#include <list>

using namespace std;
using namespace stdext;

#ifdef ONLINE_JUDGE
#include <iostream>
#else
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif

#define int long long

struct query
{
	int a, b, index;
	bool operator < (query &q)
	{
		return a < q.a || a == q.a && b < q.b;
	}
};

int n, p, cnt;
int w[400000], sum[400000];

void findSum(query &q)
{
	cnt = 0;
	for(int i = q.a%q.b; i < n; i += q.b)
	{
		sum[cnt] = w[i];
		cnt++;
	}
	for(int i = cnt-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

query v[400000];

__int32 main()
{
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> w[i];
	cin >> p;
	for(int i = 0; i < p; i++)
	{
		cin >> v[i].a >> v[i].b;
		v[i].a--;
		v[i].index = i;
	}
	vector<int> ans(p);
	sort(v,v+p);
	for(int i = 0; i < p; i++)
	{
		if(i == 0 || v[i].a != v[i-1].a || v[i].b != v[i-1].b)
			findSum(v[i]);
		ans[v[i].index] = sum[v[i].a/v[i].b];
	}
	for(int i = 0; i < p; i++)
		cout << ans[i] << endl;
}


#include <fstream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <sstream>
#include <ctime>
#include <hash_map>
#include <memory.h>
#include <queue>
#include <list>

using namespace std;
using namespace stdext;

#ifdef ONLINE_JUDGE
#include <iostream>
#else
ifstream cin("input.txt");
ofstream cout("output.txt");
#endif

#define int long long

int n, p;
vector<int> w;

map<pair<int,int>, vector<int> > ma;

void calc(int a, int b, vector<int> &sum)
{
	sum.reserve(n/b);
	for(int i = a; i < n; i += b)
		sum.push_back(w[i]);
	for(int i = (int)sum.size()-2; i >= 0; i--)
		sum[i] += sum[i+1];
}

int sum(int a, int b, vector<int> &sum)
{
	return sum[a/b];
}

__int32 main()
{
	cin >> n;
	w.resize(n);
	for(int i = 0; i < n; i++)
		cin >> w[i];
	cin >> p;
	for(int i = 0; i < p; i++)
	{
		int a,b;
		cin >> a >> b;
		a--;
		if(ma.find(make_pair(a%b,b)) == ma.end())
			calc(a%b,b,ma[make_pair(a%b,b)]);
		cout << sum(a,b,ma[make_pair(a%b,b)]) << endl;
	}
}


#include <iostream>
#include <cstdio>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <memory.h>
#include <cassert>

using namespace std;

#define fo(a,b,c) for (int a = (b); a < (c); a++)
#define fr(a,b) fo(a, 0, (b))
#define fi(n) fr(i, (n))
#define fj(n) fr(j, (n))
#define fd(a,b,c) for (int a = (b); a >= (c); a--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define _(a,b) memset((a), (b), sizeof(a))
#define __(a) memset((a), 0, sizeof(a))
#define sz(a) (int)(a).size()
#define mp make_pair
#define pb push_back

typedef long long lint;
typedef vector<int> VI;
typedef vector<string> VS;
typedef pair<int, int> PII;

void prepare()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int maxn = 300555;

struct C
{
	int a, b, num;
	bool operator < (const C &c) const
	{
		return b < c.b;
	}
};

int n, n2, kz;
int a[maxn];
lint sum[maxn], res[maxn];
C zap[maxn];

void solve()
{
	scanf("%d", &n);
	fi(n)
		scanf("%d", &a[i]);
	scanf("%d", &kz);
	fi(kz)
	{
		scanf("%d%d", &zap[i].a, &zap[i].b);
		zap[i].a--;
		zap[i].num = i;
	}
	sort(zap, zap + kz);
	int i = 0, j = 0;
	while (i < kz && zap[i].b < 550)
	{
		while (zap[j].b == zap[i].b)
			j++;
		fd(k, n - 1, 0)
			sum[k] = sum[k + zap[i].b] + a[k];
		fo(k, i, j)
			res[zap[k].num] = sum[zap[k].a];
		i = j;
	}
	for (; i < kz; i++)
	{
		for (int k = zap[i].a; k < n; k += zap[i].b)
			res[zap[i].num] += a[k];
	}
	fi(kz)
		printf("%I64d\n", res[i]);
}

int main()
{
	prepare();
	solve();
	return 0;
}


#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <utility>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) ((S&two(X))>0)
#define containL(S,X) ((S&twoL(X))>0)
typedef pair<int,int> PII;
int countbit(int n) {return (n==0)?0:(1+countbit(n&(n-1)));}
int lowbit(int n) {return (n^(n-1))&n;}
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> T sqr(T x) {return x*x;}
template<class T> void checkmin(T &a,T b) {if (b<a) a=b;}
template<class T> void checkmax(T &a,T b) {if (b>a) a=b;}
#define SIZE(X) ((int)((X).size()))
#define LENGTH(X) ((int)((X).length()))
#define MP(A,B) make_pair(A,B)
#define	MAXN 300010

int cow[MAXN];
int N, M;
pair< PII, int > pr[MAXN];
int ans[MAXN];
int mem[MAXN];

bool cmp( const pair< PII, int > &a, const pair< PII, int > &b )
{
	return a.first.second < b.first.second;
}

int main()
{
	//freopen( "in.txt", "r", stdin );
	scanf( "%d", &N );
	for( int i = 0; i < N; ++ i )
		scanf( "%d", &cow[i] );
	scanf( "%d", &M );
	for( int i = 0; i < M; ++ i )
	{
		int a, b;
		scanf( "%d %d", &a, &b );
		a --;
		pr[i] = MP( MP( a, b ), i );
	}
	sort( pr, pr + M, cmp );
	int itv = -1;
	for( int i = 0; i < M; ++ i )
	{
		int id = pr[i].second;
		int a = pr[i].first.first, b = pr[i].first.second;
		if( b <= 600 )
		{
			if( b != itv )
			{
				memset( mem, 0, sizeof( mem ) );
				itv = b;
				for( int j = N - 1; j >= 0; -- j )
				{
					mem[j] = j + b >= N ? cow[j] : mem[j + b] + cow[j];
				}
				ans[id] = mem[a];
			}
			else
				ans[id] = mem[a];
		}
		else
		{
			ans[id] = 0;
			for( int j = a; j < N; j += b )
			{
				ans[id] += cow[j];
			}
		}
	}
	for( int i = 0; i < M; ++ i )
		printf( "%d\n", ans[i] );

	return 0;
}


#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <functional>
#include <utility>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string.h>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define two(X) (1<<(X))
#define twoL(X) (((int64)(1))<<(X))
#define contain(S,X) ((S&two(X))>0)
#define containL(S,X) ((S&twoL(X))>0)
typedef pair<int,int> PII;
int countbit(int n) {return (n==0)?0:(1+countbit(n&(n-1)));}
int lowbit(int n) {return (n^(n-1))&n;}
const double pi=acos(-1.0);
const double eps=1e-11;
template<class T> T sqr(T x) {return x*x;}
template<class T> void checkmin(T &a,T b) {if (b<a) a=b;}
template<class T> void checkmax(T &a,T b) {if (b>a) a=b;}
#define SIZE(X) ((int)((X).size()))
#define LENGTH(X) ((int)((X).length()))
#define MP(A,B) make_pair(A,B)
#define	MAXN 300010

int cow[MAXN];
int N, M;
pair< PII, int > pr[MAXN];
LL ans[MAXN];
LL mem[MAXN];

bool cmp( const pair< PII, int > &a, const pair< PII, int > &b )
{
	return a.first.second < b.first.second;
}

int main()
{
	//freopen( "in.txt", "r", stdin );
	scanf( "%d", &N );
	for( int i = 0; i < N; ++ i )
		scanf( "%d", &cow[i] );
	scanf( "%d", &M );
	for( int i = 0; i < M; ++ i )
	{
		int a, b;
		scanf( "%d %d", &a, &b );
		a --;
		pr[i] = MP( MP( a, b ), i );
	}
	sort( pr, pr + M, cmp );
	int itv = -1;
	for( int i = 0; i < M; ++ i )
	{
		int id = pr[i].second;
		int a = pr[i].first.first, b = pr[i].first.second;
		if( b <= 600 )
		{
			if( b != itv )
			{
				memset( mem, 0, sizeof( mem ) );
				itv = b;
				for( int j = N - 1; j >= 0; -- j )
				{
					mem[j] = j + b >= N ? cow[j] : mem[j + b] + cow[j];
				}
				ans[id] = mem[a];
			}
			else
				ans[id] = mem[a];
		}
		else
		{
			ans[id] = 0;
			for( int j = a; j < N; j += b )
			{
				ans[id] += cow[j];
			}
		}
	}
	for( int i = 0; i < M; ++ i )
		cout << ans[i] << endl;

	return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<algorithm>
#include<iterator>
#include<vector>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn=3e5+10;
int block,n,q,a[maxn];
ll ans[maxn],sum[maxn];
struct query
{
	int id,pos;
	query(int _id=0,int _pos=0):id(_id),pos(_pos){}
};
vector<query> d[maxn];
void init()
{
	block=(int)sqrt(n+0.5);
	for(int i=1;i<maxn;i++)
	{
		if(d[i].empty())
			continue;
		if(i>block)//对于b>sqrt(n)的询问,我们暴力计算
		{
			for(int j=0;j<d[i].size();j++)
			{
				ll res=0;
				for(int k=d[i][j].pos;k<=n;k+=i)
					res+=a[k];
				ans[d[i][j].id]=res;
			}
		}
		else//b<=sqrt(N)的询问先记下来,然后我们再跑 sqrt(N) 次查找,每次处理出步长为i,从每个位置向后能够得到的牛个数
		{
			memset(sum,0,sizeof(sum));
			for(int j=n;j>0;j--)
				sum[j]=a[j]+(j+i<=n?sum[i+j]:0);
			for(int j=0;j<d[i].size();j++)
				ans[d[i][j].id]=sum[d[i][j].pos];
		}
		d[i].clear();
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int pos,id;
		scanf("%d%d",&pos,&id);
		d[id].push_back(query(i,pos));
	}
	init();
	for(int i=1;i<=q;i++)
		cout<<ans[i]<<endl;
	return 0;
}


#include<iostream>
#include<cstdio>
#include<stack>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<algorithm>
#include<iterator>
#include<vector>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
const int maxn=3e5+10;
int block,n,q,a[maxn];
ll ans[maxn],sum[maxn];
struct query
{
	int id,pos;
	query(int _id=0,int _pos=0):id(_id),pos(_pos){}
};
vector<query> d[maxn];
void init()
{
	block=(int)sqrt(n+0.5);
	for(int i=1;i<maxn;i++)
	{
		if(d[i].empty())
			continue;
		if(i>block)//对于b>sqrt(n)的询问,我们暴力计算
		{
			for(int j=0;j<d[i].size();j++)
			{
				ll res=0;
				for(int k=d[i][j].pos;k<=n;k+=i)
					res+=a[k];
				ans[d[i][j].id]=res;
			}
		}
		else//b<=sqrt(N)的询问先记下来,然后我们再跑 sqrt(N) 次查找,每次处理出步长为i,从每个位置向后能够得到的牛个数
		{
			memset(sum,0,sizeof(sum));
			for(int j=n;j>0;j--)
				sum[j]=a[j]+(j+i<=n?sum[i+j]:0);
			for(int j=0;j<d[i].size();j++)
				ans[d[i][j].id]=sum[d[i][j].pos];
		}
		d[i].clear();
	}
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	scanf("%d",&q);
	for(int i=1;i<=q;i++)
	{
		int pos,id;
		scanf("%d%d",&pos,&id);
		d[id].push_back(query(i,pos));
	}
	init();
	for(int i=1;i<=q;i++)
		cin<<ans[i]<<endl;
	return 0;
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    vector <long long int> s;
    ab()
    {
        i.resize(0);
        s.resize(0);
    }
};
const int tt=1000;
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(tt);
int main()
{
    for (int i=0;i<tt;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (c[i].b>tt) for (int j=c[i].a-1;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<tt;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        d[i][j].s.push_back(0);
        for (int k=j;k<n;k+=i+1) d[i][j].s.push_back(d[i][j].s[d[i][j].s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=d[i][j].s[d[i][j].s.size()-1]-d[i][j].s[(c[d[i][j].i[k]].a-1)/(i+1)];
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    vector <long long int> s;
    ab()
    {
        i.resize(0);
        s.resize(0);
    }
};
const int tt=1001;
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(tt);
int main()
{
    for (int i=0;i<tt;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (c[i].b>tt) for (int j=c[i].a;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<tt;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        d[i][j].s.push_back(0);
        for (int k=j;k<n;k+=i+1) d[i][j].s.push_back(d[i][j].s[d[i][j].s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=d[i][j].s[d[i][j].s.size()-1]-d[i][j].s[(c[d[i][j].i[k]].a-1)/(i+1)];
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    ab()
    {
        i.resize(0);
    }
};
const int tt=1000;
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(tt);
vector <long long int> s;
int main()
{
    for (int i=0;i<tt;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (c[i].b>tt) for (int j=c[i].a-1;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<tt;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        s.assign(1,0);
        for (int k=j;k<n;k+=i+1) s.push_back(s[s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=s[s.size()-1]-s[(c[d[i][j].i[k]].a-1)/(i+1)];
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    vector <long long int> s;
    ab()
    {
        i.resize(0);
        s.resize(0);
    }
};
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(1000);
int main()
{
    for (int i=0;i<1000;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (c[i].b>1000) for (int j=c[i].a;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<1000;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        d[i][j].s.push_back(0);
        for (int k=j;k<n;k+=i+1) d[i][j].s.push_back(d[i][j].s[d[i][j].s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=d[i][j].s[d[i][j].s.size()-1]-d[i][j].s[(c[d[i][j].i[k]].a-1)/(i+1)];
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    vector <long long int> s;
    ab()
    {
        i.resize(0);
        s.resize(0);
    }
};
const int tt=1000;
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(tt);
int main()
{
    for (int i=0;i<tt;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (n==2890) printf("%d %d\n",c[i].a,c[i].b);
        if (c[i].b>tt) for (int j=c[i].a;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<tt;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        d[i][j].s.push_back(0);
        for (int k=j;k<n;k+=i+1) d[i][j].s.push_back(d[i][j].s[d[i][j].s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=d[i][j].s[d[i][j].s.size()-1]-d[i][j].s[(c[d[i][j].i[k]].a-1)/(i+1)];
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <stdio.h>
#include <vector>
using namespace std;
struct sc
{
    int a,b;
    long long int s;
};
struct ab
{
    vector <int> i;
    vector <long long int> s;
    ab()
    {
        i.resize(0);
        s.resize(0);
    }
};
int n,p;
vector <int> w;
vector <sc> c;
vector <vector <ab> > d(1000);
int main()
{
    for (int i=0;i<1000;i++) d[i].resize(i+1);
    scanf("%d",&n);
    w.resize(n);
    for (int i=0;i<n;i++) scanf("%d",&w[i]);
    scanf("%d",&p);
    c.resize(p);
    for (int i=0;i<p;i++) scanf("%d%d",&c[i].a,&c[i].b);
    for (int i=0;i<p;i++)
    {
        if (c[i].b>1000) for (int j=c[i].a;j<n;j+=c[i].b) c[i].s+=w[j];
        else d[c[i].b-1][(c[i].a-1)%c[i].b].i.push_back(i);
    }
    for (int i=0;i<1000;i++) for (int j=0;j<=i;j++) if (d[i][j].i.size()>0)
    {
        d[i][j].s.push_back(0);
        for (int k=j;k<n;k+=i+1) d[i][j].s.push_back(d[i][j].s[d[i][j].s.size()-1]+w[k]);
        for (int k=0;k<d[i][j].i.size();k++) c[d[i][j].i[k]].s=d[i][j].s[d[i][j].s.size()-1]-(c[d[i][j].i[k]].a-1)/(i+1);
    }
    for (int i=0;i<p;i++) printf("%I64d\n",c[i].s);
}


#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
void main () {
    int n;
    cin >> n;
    vector<ll> w(n);
    for (int i = 0; i < n; ++i)
        cin >> w[i];
    int p;
    cin >> p;
    vector<ll> aa(p),bb(p),res(p);
    for (int i = 0; i < p; ++i) {
        cin >> aa[i] >> bb[i];
        aa[i]--;
        if (bb[i] >= 500) {
            ll lres = 0;
            for (int j = aa[i]; j < n; j+=bb[i])
                lres += w[j];
            res[i] = lres;
        }
    }

    vector< vector<ll> > dp(500, vector<ll> (n,0));
    for (int b = 1; b < 500; ++b) {
        int m = max(n-b,0);
        for (int a = n-1; a >= m; --a) {
            dp[b][a] = w[a];
        }
        for (int a = m-1; a >= 0; --a) {
            dp[b][a] = dp[b][a+b] + w[a];
        }
    }

    for (int i = 0; i < p; ++i) {
        if (bb[i] >= 500) {
            cout << res[i] << endl;
        } else {
            cout << dp[bb[i]][aa[i]] << endl;
        }
    }
}


#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
void main () {
    int n;
    cin >> n;
    vector<ll> w(n);
    for (int i = 0; i < n; ++i)
        cin >> w[i];
    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        int a,b;
        cin >> a >> b;
        ll res = 0;
        for (int j = a-1; j < n; j+=b)
            res += w[j];
        cout << res << endl;
    }
}


#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
void main () {
    int n;
    cin >> n;
    vector<ll> w(n);
    for (int i = 0; i < n; ++i)
        cin >> w[i];

    ll a, b;
    vector< vector<ll> > dp(450, vector<ll> (n,0));
    for (b = 1; b < 450; ++b) {
        ll m = max(n-b,0);
        for (a = n-1; a >= m; --a) {
            dp[b][a] = w[a];
        }
        for (a = m-1; a >= 0; --a) {
            dp[b][a] = dp[b][a+b] + w[a];
        }
    }

    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        cin >> a >> b;
        a--;
        if (b >= 450) {
            ll res = 0;
            for (int j = a; j < n; j+=b)
                res += w[j];
            cout << res << endl;
        } else {
            cout << dp[b][a] << endl;
        }
    }
}


#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
void main () {
    int n;
    cin >> n;
    vector<ll> w(n);
    for (int i = 0; i < n; ++i)
        cin >> w[i];

    int a, b;
    vector< vector<ll> > dp(450, vector<ll> (n,0));
    for (b = 1; b < 450; ++b) {
        int m = max(n-b,0);
        for (a = n-1; a >= m; --a) {
            dp[b][a] = w[a];
        }
        for (a = m-1; a >= 0; --a) {
            dp[b][a] = dp[b][a+b] + w[a];
        }
    }

    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        cin >> a >> b;
        a--;
        if (b >= 450) {
            ll res = 0;
            for (int j = a; j < n; j+=b)
                res += w[j];
            cout << res << endl;
        } else {
            cout << dp[b][a] << endl;
        }
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
struct tmp {
    ll a,b,n,ans;
};
bool comp (tmp& a, tmp& b) {
    return a.b < b.b;
}
bool comp2 (tmp& a, tmp& b) {
    return a.n < b.n;
}
#define BORDER 500
void main () {
    int n;
    cin >> n;
    vector<ll> w(n,0);
    for (int i = 0; i < n; ++i)
        cin >> w[i];
    int p;
    cin >> p;
    vector<tmp> t(p);
    for (int i = 0; i < p; ++i) {
        cin >> t[i].a >> t[i].b;
        t[i].a--;
        t[i].n = i;
    }
    sort (t.begin(), t.end(), comp);

    vector<ll> dp(n+1);
    for (int i = 0; i < p; ++i) {
        if (t[i].b < BORDER) {
            if (i == 0 || t[i].b != t[i-1].b) {
                for (int j = n-1; j >= 0; --j) {
                    if (n-j <= t[i].b) dp[j] = w[j];
                    else dp[j] = dp[j+t[i].b] + w[j];
                }
            }
            t[i].ans = dp[t[i].a];
        } else {
            t[i].ans = 0;
            for (int j = t[i].a; j < n; j+=t[i].b)
                t[i].ans += w[j];
        }
    }

    sort (t.begin(), t.end(), comp2);
    for (int i = 0; i < p; ++i) {
        cout << t[i].ans << endl;
    }
}


#include <iostream>
#include <vector>
typedef long long ll;
using namespace std;
void main () {
    int n;
    cin >> n;
    vector<ll> w(n);
    for (int i = 0; i < n; ++i)
        cin >> w[i];
    int p;
    cin >> p;
    for (int i = 0; i < p; ++i) {
        int a,b;
        cin >> a >> b;
        ll res = 0;
        for (int j = a-1; j < n; j+=b)
            res += w[j];
        cout << res;
    }
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define mx 200001
long long dp[mx][450]={0};
int ar[mx];
int n;
void calc(int x, int y){
    long long lst =0;
    if(dp[x][y]!=0) return ;
    while(x>0){
        dp[x][y]=ar[x]+lst;
        lst=dp[x][y];
        x-=y;
    }
}
long long ans(int x, int y){
    long long tot=0;
    while(x<=n){
        tot+=ar[x];
        x+=y;
    }
    return tot;
}
int main(){

    scanf("%d",&n);
    for(int i=1;i<=n;++i)
        scanf("%d",&ar[i]);
    int sqr = sqrt(n*1.0);
    for(int i=n;i>=n-sqr;--i)
        for(int j=1;j<=sqr;++j)
            calc(i,j);
    int q;
    scanf("%d",&q);
    while(q--){
        int x,y;
        scanf("%d%d",&x,&y);
        if(y>sqr)printf("%I64d\n",ans(x,y));
        else printf("%I64d\n",dp[x][y]);
    }
}


#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
int a[300005];
LL r[300005];
vector<pair<pair<int, int>, int> > Q;
LL ans[300005];

int main(void) {
    int n, p;
    scanf("%d", &n);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    scanf("%d", &p);
    for(int i=0;i<p;i++) {
        int A, B;
        scanf("%d%d", &A, &B);
        Q.push_back(make_pair(make_pair(B, A), i));
    }
    sort(Q.begin(), Q.end());
    for(int i=0,j=0;i<(int)Q.size();i=j) {
        while(j<(int)Q.size() && Q[j].first.first == Q[i].first.first)++j;
        int B = Q[i].first.first;
        if(B >= 600) {
            for(int k=i;k<j;k++) {
                int A = Q[k].first.second;
                LL v=0;
                for(int s=A;s<=n;s+=B) v+=a[s];
                ans[Q[k].second] = v;
            }
        } else {
            for(int k=n;k>=1;--k) {
                r[k]=a[k];
                if(k+B<=n) r[k]+=r[k+B];
            }
            for(int k=i;k<j;k++) {
                int A = Q[k].first.second;
                ans[Q[k].second] = r[A];
            }
        }
    }
    for(int i=0;i<p;i++)
        printf("%I64d\n", ans[i]);
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
#define mx 200001
long long dp[mx][450]={0};
int ar[mx];
int n;
void calc(int x, int y){
	long long lst =0;
	if(dp[x][y]!=0) return ;
	while(x>0){
		dp[x][y]=ar[x]+lst;
		lst=dp[x][y];
		x-=y;
	}
}
long long ans(int x, int y){
	long long tot=0;
	while(x<=n){
		tot+=ar[x];
		x+=y;
	}
	return tot;
}
int main(){

	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&ar[i]);
	int sqr = sqrt(n);
	for(int i=n;i>=n-sqr;--i)
		for(int j=1;j<=sqr;++j)
			calc(i,j);
	int q;
	scanf("%d",&q);
	while(q--){
		int x,y;
		scanf("%d%d",&x,&y);
		if(y>sqr)printf("%I64d\n",ans(x,y));
		else printf("%I64d\n",dp[x][y]);
	}
}


#include <iostream>
#include <sstream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define _(a,b) memset( (a), b, sizeof( a ) )
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

typedef unsigned long long ull;
typedef long long lint;
typedef pair < int , int > pii;
typedef long double ld;

const int inf = 1000 * 1000 * 1000;
const lint linf = 1000000000000000000LL;
const double eps = 1e-9;

void prepare( )
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int len = 1000;

int n;
int a[300005];
lint ans[300005];
pair < pii , int > q[300005];
lint sum[300005];

bool solve( )
{
	scanf("%d",&n);
	for ( int i = 0; i < n; i ++ )
		scanf("%d",&a[i]);
	int m;
	scanf("%d",&m);
	for ( int i = 0; i < m; i ++ )
	{
		scanf("%d%d",&q[i].first.second,&q[i].first.first);
		q[i].first.second --;
		q[i].second = i;
	}
	sort(q,q+m);

	int step = 0;
	for ( int i = 0; i < m; i ++ )
	{
		int x,add,id;
		id = q[i].second;
		add = q[i].first.first;
		x = q[i].first.second;
		if (add > len)
		{
			while (x < n)
			{
				ans[id] += a[x];
				x += add;
			}
		}
		else
		{
			if (add > step)
			{
				step = add;
				_(sum,0);
				for ( int j = n - 1; j >= 0; j -- )
				{
					sum[j] = a[j] + ((j + step < n) ? sum[j+step] : 0);
				}
			}
			ans[id] = sum[x];
		}
	}
	for ( int i = 0; i < m; i ++ )
		cout << ans[i] << endl;
	return false;
}

int main()
{
	prepare( );
	while ( solve() );
	return 0;
}


#include <iostream>
#include <sstream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define _(a,b) memset( (a), b, sizeof( a ) )
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

typedef unsigned long long ull;
typedef long long lint;
typedef pair < int , int > pii;
typedef long double ld;

const int inf = 1000 * 1000 * 1000;
const lint linf = 1000000000000000000LL;
const double eps = 1e-9;

void prepare( )
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int len = 2000;

int n;
int a[300005];
lint sum[155][155][155];

bool solve( )
{
	scanf("%d",&n);
	for ( int i = 0; i < n; i ++ )
		scanf("%d",&a[i]);

	lint cur = 0;
	for ( int i = 0; i < n; i += len )
	{
		for ( int j = i; j < min(n,i + len); j ++ )
		{
			for ( int k = 1; k < min(i + len,155); k ++ )
			{
				cur = 0;
				for ( int p = j; p < min(i + len,n); p += k )
				{
					cur += a[p];
				}
				sum[i][j][k] = cur;
			}
		}
	}

	int it,x,y;
	scanf("%d",&it);
	lint ans = 0;
	for ( int its = 0; its < it; its ++ )
	{
		ans = 0;
		scanf("%d%d",&x,&y);
		x --;
		if (y > len)
		{
			for ( int p = x; p < n; p += y)
			{
				ans += a[p];
			}
		}
		else
		{
			int np = x / len;
			int pos = x;
			for (int i = np; i < 155; i ++ )
			{
				if (pos >= n)
					break;
				//if (y >= 76)
				//	ans += a[pos];
				ans += sum[i][pos - i * len][y];
				int k = ((i+1)*len - pos + (y - 1)) / y;
				pos = pos + k * y;
			}
		}
		cout << ans << endl;
	}
	return false;
}

int main()
{
	prepare( );
	while ( solve() );
	return 0;
}


#include <iostream>
#include <sstream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define _(a,b) memset( (a), b, sizeof( a ) )
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

typedef unsigned long long ull;
typedef long long lint;
typedef pair < int , int > pii;
typedef long double ld;

const int inf = 1000 * 1000 * 1000;
const lint linf = 1000000000000000000LL;
const double eps = 1e-9;

void prepare( )
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int len = 1000;

int n;
int a[300005];
lint ans[300005];
pair < pii , int > q[300005];
lint sum[300005];

bool solve( )
{
	scanf("%d",&n);
	for ( int i = 0; i < n; i ++ )
		scanf("%d",&a[i]);
	int m;
	scanf("%d",&m);
	for ( int i = 0; i < m; i ++ )
	{
		scanf("%d%d",&q[i].first.second,&q[i].first.first);
		q[i].first.second --;
		q[i].second = i;
	}
	sort(q,q+m);

	int step = 0;
	for ( int i = 0; i < m; i ++ )
	{
		int x,add,id;
		id = q[i].second;
		add = q[i].first.first;
		x = q[i].first.second;
		if (add > len)
		{
			while (x < n)
			{
				sum[id] += a[x];
				id += add;
			}
		}
		else
		{
			if (add > step)
			{
				step = add;
				_(sum,0);
				for ( int j = n - 1; j >= 0; j -- )
				{
					sum[j] = a[j] + ((j + step < n) ? sum[j+step] : 0);
				}
			}
			ans[id] = sum[x];
		}
	}
	for ( int i = 0; i < m; i ++ )
		cout << ans[i] << endl;
	return false;
}

int main()
{
	prepare( );
	while ( solve() );
	return 0;
}


#include <iostream>
#include <sstream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define _(a,b) memset( (a), b, sizeof( a ) )
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

typedef unsigned long long ull;
typedef long long lint;
typedef pair < int , int > pii;
typedef long double ld;

const int inf = 1000 * 1000 * 1000;
const lint linf = 1000000000000000000LL;
const double eps = 1e-9;

void prepare( )
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int len = 2000;

int n;
int a[300005];
lint sum[155][155][155];

bool solve( )
{
	scanf("%d",&n);
	for ( int i = 0; i < n; i ++ )
		scanf("%d",&a[i]);

	lint cur = 0;
	for ( int i = 0; i < n; i += len )
	{
		for ( int j = i; j < min(n,i + len); j ++ )
		{
			for ( int k = 1; k < min(i + len,155); k ++ )
			{
				cur = 0;
				for ( int p = j; p < min(i + len,n); p += k )
				{
					cur += a[p];
				}
				sum[i][j - i][k] = cur;
			}
		}
	}

	int it,x,y;
	scanf("%d",&it);
	lint ans = 0;
	for ( int its = 0; its < it; its ++ )
	{
		ans = 0;
		scanf("%d%d",&x,&y);
		x --;
		if (y > len)
		{
			for ( int p = x; p < n; p += y)
			{
				ans += a[p];
			}
		}
		else
		{
			int np = x / len;
			int pos = x;
			for (int i = np; i < 155; i ++ )
			{
				if (pos >= n)
					break;
				//if (y >= 76)
				//	ans += a[pos];
				ans += sum[i][pos - i * len][y];
				int k = ((i+1)*len - pos + (y - 1)) / y;
				pos = pos + k * y;
			}
		}
		cout << ans << endl;
	}
	return false;
}

int main()
{
	prepare( );
	while ( solve() );
	return 0;
}


#include <iostream>
#include <sstream>
#include <stdio.h>
#include <memory.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <cassert>

using namespace std;

#define mp make_pair
#define pb push_back
#define _(a,b) memset( (a), b, sizeof( a ) )
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()

typedef unsigned long long ull;
typedef long long lint;
typedef pair < int , int > pii;
typedef long double ld;

const int inf = 1000 * 1000 * 1000;
const lint linf = 1000000000000000000LL;
const double eps = 1e-9;

void prepare( )
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
}

const int len = 500;

int n;
int a[300005];
lint sum[605][501][251];

bool solve( )
{
	scanf("%d",&n);
	for ( int i = 0; i < n; i ++ )
		scanf("%d",&a[i]);

	lint cur = 0;
	for ( int i = 0; i < n; i+= len )
	{
		for ( int j = i; j < min(n,i + len); j ++ )
		{
			for ( int k = 1; k < min(i + len,251); k ++ )
			{
				cur = 0;
				for ( int p = j; p < min(i + len,n); p += k )
				{
					cur += a[p];
				}
				sum[i][j][k] = cur;
			}
		}
	}

	int it,x,y;
	scanf("%d",&it);
	lint ans = 0;
	for ( int its = 0; its < it; its ++ )
	{
		ans = 0;
		scanf("%d%d",&x,&y);
		x --;
		if (y > len)
		{
			for ( int p = x; p < n; p += y)
			{
				ans += a[p];
			}
		}
		else
		{
			int np = x / len;
			int pos = x;
			for (int i = np; i < 605; i ++ )
			{
				if (pos >= n)
					break;
				if (y >= 251)
					ans += a[pos];
				ans += sum[i][pos][y];
				int k = ((i+1)*len - pos + (y - 1)) / y;
				pos = pos + k * y;
			}
		}
		cout << ans << endl;
	}
	return false;
}

int main()
{
	prepare( );
	while ( solve() );
	return 0;
}


#include <iostream>
using namespace std;

int main() {

  int n, input;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input;
    for (int i = 0; i < input; i++) {
      if (i == n-1) { cout << "PLR"; return 0; } else { cout << "PRL"; }
    }
    cout << "R";
  }
}


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main() {

  int n, input;
  cin >> n;
  for (int i = 0; i < n-1; i++) {
    cin >> input;
    while (input-- > 0) {
      cout << "PRL";
    }
    if (input == -1) { cout << "R"; }
  }
  cin >> input;
  while (input-- > 0) {
    cout << "PLR";
  }
}


#include <iostream>
using namespace std;

int main() {

  int n, input;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input;
    for (int j = 0; j < input; j++) {
      if (i == n-1) { cout << "PLR"; } else { cout << "PRL"; }
    }
    if (i == n-1) { return 0; }
    cout << "R";
  }
}


#include <iostream>
using namespace std;

int main() {

  int n, input;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> input;
    for (int j = 0; j < input; j++) {
      if (i == n-1) { cout << "PLR"; } else { cout << "PRL"; }
    }
    if (i < n) { cout << "R"; }
    cout << "R";
  }
}


#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#define lli long long int
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n-1;i>=x;i--)
#define st set<lli>
#define v vector<lli>
#define um unordered_map<lli,lli>
#define vpl vector<pair<lli,lli>>
#define llu long long unsigned
#define ms muliset<int,greater<int>>
#define ums unordered_map<string,lli>
#define pb push_back
#define mod 1000000007
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test lli t; cin>>t; while(t--)
using namespace std;
lli gcd(lli a,lli b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
v adj[300001];
lli vist[300001],oil[300001],maxy=0,cc[300001];
ums path;

void dfs(lli node)
{
    vist[node]=1;
    lli c2=0;
    for(lli child : adj[node]) if(vist[child]) c2++;
    if(c2==adj[node].size()) maxy=max(cc[node],maxy);
    for(lli child : adj[node])
    {
        if(!vist[child] && cc[node]>=path[node+" "+child])
        {
            cc[child]=cc[node]+oil[child]-path[node+" "+child];
            dfs(child);
        }
    }
}

int main()
{
    time
    int n;
        cin>>n;
        int a[n];
        for(int i=0;i<n;i++) cin>>a[i];
        string s = "";
        int c;
        while(1){
           c=0;
           for(int i=0;i<n-1;i++){
              if(a[i]>0) a[i]--,s+="PR",c++;
              else s+="R";
           }
           for(int i=n-1;i>=1;i--){
             if(a[i]>0) a[i]--,s+="PL",c++;
             else s+="L";
           }
           if(c==0) break;
        }
        int i = s.size()-1;
        while(i>=0&&s[i]!='P') i--;
        for(int j=0;j<=i;j++) cout<<s[j];
    return 0;
}


#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#define lli long long int
#define loop(i,x,n) for(int i=x;i<n;i++)
#define loopr(i,x,n) for(int i=n-1;i>=x;i--)
#define st set<lli>
#define v vector<lli>
#define um unordered_map<lli,lli>
#define vpl vector<pair<lli,lli>>
#define llu long long unsigned
#define ms muliset<int,greater<int>>
#define ums unordered_map<string,lli>
#define pb push_back
#define mod 1000000007
#define time ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define test lli t; cin>>t; while(t--)
using namespace std;
lli gcd(lli a,lli b)
{
    if(b==0) return a;
    return gcd(b,a%b);
}
v adj[300001];
lli vist[300001],oil[300001],maxy=0,cc[300001];
ums path;

void dfs(lli node)
{
    vist[node]=1;
    lli c2=0;
    for(lli child : adj[node]) if(vist[child]) c2++;
    if(c2==adj[node].size()) maxy=max(cc[node],maxy);
    for(lli child : adj[node])
    {
        if(!vist[child] && cc[node]>=path[node+" "+child])
        {
            cc[child]=cc[node]+oil[child]-path[node+" "+child];
            dfs(child);
        }
    }
}

int main()
{
    time
    lli n;
    cin>>n;
    lli a[n];
    loop(i,0,n) cin>>a[i];
    lli cur=0,j=0;
    while(cur<n)
    {
        if(a[cur]) cout<<"P",a[cur]--;
        if(!j) cout<<"R",cur++;
        if(a[cur]) j=1-j;
        if(a[cur]) cout<<"P",a[cur]--;
        if(!a[n-1] && !a[n-2]) break;
        if(j && a[cur]) cout<<"L",cur--;
        j=1-j;
    }
    return 0;
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;
#define ll long long
#define in int
#define pb push_back
const ll papa = 10009;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    in a[papa];
    in n; cin >>  n;
    in sum = 0;
    in round = 0;
    for(in i=0; i<n; ++i) cin >> a[i], sum += a[i];
    while (sum)
    {
        for(in i=0; i<n-1; i++){
            if(a[i] > 0){
                cout << 'P';
                sum--;
                if(sum) cout << 'R';
                else break;
                a[i]--;
            }
            else cout << "R";
        }
        if(sum == 0) break;
        for(in i=n-1; i>0; i--){
            if(a[i] > 0){
                cout << 'P';
                sum--;
                if(sum) cout << 'L';
                else break;
                a[i]--;
            }
            else cout << 'L';
        }
    }
}


#include <iostream>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <string>

using namespace std;
#define ll long long
#define in int
#define pb push_back
const ll papa = 109;

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    in a[papa];
    in n; cin >>  n;
    in sum = 0;
    in round = 0;
    for(in i=0; i<n; ++i) cin >> a[i], sum += a[i];
    while (sum)
    {
        for(in i=0; i<n-1; i++){
            if(a[i] > 0){
                cout << 'P';
                sum--;
                if(sum) cout << 'R';
                else break;
                a[i]--;
            }
            else cout << "R";
        }
        if(sum == 0) break;
        for(in i=n-1; i>0; i--){
            if(a[i] > 0){
                cout << 'P';
                sum--;
                if(sum) cout << 'L';
                else break;
                a[i]--;
            }
            else cout << 'L';
        }
    }
}


#include <bits/stdc++.h>

// ---------------------------template starts here--------------------------

#define int long long int
#define pb push_back
#define MAX LLONG_MAX
#define endl "\n"
#define precise std::cout << std::fixed;std::cout << std::setprecision(6);
#define zerobits(x) __builtin_ctzll(z)
#define print(v) for(int x : v) cout << x << endl;
#define F first
#define S second
#define mp make_pair
#define MIN LLONG_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
vector <pair <int, int> > factors;

void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {
    int res = 1;     // Initialize result
    x = x % p; // Update x if it is more than or
                // equal to p

    while (y > 0)  {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

bool is_prime(int n) {
    if(n < 2)
        return false;
    if(n == 2 || n == 3)
        return true;
    for(int i=2;i*i<=n;i++) {
        if(n%i == 0)
            return false;
    }
    return true;
}

bool sortbydec(const pair <int, int> &a, const pair <int, int> &b) {
    return (a.first > b.first);
}

void primeFactors(int n) {
    // Print the number of 2s that divide n
    if(n%2 == 0) {
        int count = 0;
        while (n % 2 == 0) {
            count++;
            n = n/2;
        }
        factors.pb(mp(2, count));
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        // While i divides n, print i and divide n
        if(n%i == 0) {
            int count = 0;
            while (n % i == 0) {
                count++;
                n = n/i;
            }
            factors.pb(mp(i, count));
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        factors.pb(mp(n, 1));
}

int lcm(int a, int b) {
    return (a*b)/(__gcd(a, b));
}

// number of power of v in n!
int get(int n, int v) {

    int cur = v,res = 0;

    while (cur <= n) {
        res += n / cur;
        if (cur > n / v)
            break;
        cur *= v;
    }

    return res;
}

// --------------------------template ends here------------------------------

void solve() {

    int t;
    // cin >> t;
    t = 1;

    while(t--) {

        int n;
        cin >> n;

        vector <int> v(n);

        for(auto &it : v)
            cin >> it;

        string ans = "";

        for(int i=0;i<n-1;i++) {
            int req = v[i];
            if(req > 0) {
                while(req > 0) {
                    ans += 'P';
                    ans += 'R';
                    ans += 'L';
                    req--;
                }
            }
            else
                ans += 'R';
        }

        int req = v[n-1];
        if(req > 0) {
            while(req > 0) {
                ans += 'P';
                ans += 'L';
                ans += 'R';
                req--;
            }
        }
        else
            ans += 'L';

        cout << ans << endl;

    }

    return;
}

int32_t main() {

    FO;

    auto start = std::chrono::high_resolution_clock::now();

    solve();

    auto finish = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = finish - start;
    cerr << "Elapsed time: " << elapsed.count() << " s\n";

}


#include <bits/stdc++.h>

// ---------------------------template starts here--------------------------

#define int long long int
#define pb push_back
#define MAX LLONG_MAX
#define endl "\n"
#define precise std::cout << std::fixed;std::cout << std::setprecision(6);
#define zerobits(x) __builtin_ctzll(z)
#define print(v) for(int x : v) cout << x << endl;
#define F first
#define S second
#define mp make_pair
#define MIN LLONG_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

set <int> s;
bool ar[100001];
vector <pair <int, int> > factors;

void seive() {
    ar[0] = ar[1] = true;

    for(int p=2; p*p<=100001; p++) {
        if(ar[p] == false) {
            for(int i=p*p;i<=100001;i+=p)
                ar[i] = true ;
        }
    }

    for(int p=2;p<=100001;p++) {
        if(ar[p] == false)
            s.insert(p);
    }
}

bool is_palindrome(string str) {
    int len = str.length();
    for(int i=0;i<=len/2;i++) {
        if(str[i] != str[len-1-i])
            return false;
    }
    return true;
}

int binexpo(int x, int y, int p) {
    int res = 1;     // Initialize result
    x = x % p; // Update x if it is more than or
                // equal to p

    while (y > 0)  {
        // If y is odd, multiply x with result
        if (y & 1)
            res = (res*x) % p;

        // y must be even now
        y = y>>1; // y = y/2
        x = (x*x) % p;
    }
    return res;
}

bool is_prime(int n) {
    if(n < 2)
        return false;
    if(n == 2 || n == 3)
        return true;
    for(int i=2;i*i<=n;i++) {
        if(n%i == 0)
            return false;
    }
    return true;
}

bool sortbydec(const pair <int, int> &a, const pair <int, int> &b) {
    return (a.first > b.first);
}

void primeFactors(int n) {
    // Print the number of 2s that divide n
    if(n%2 == 0) {
        int count = 0;
        while (n % 2 == 0) {
            count++;
            n = n/2;
        }
        factors.pb(mp(2, count));
    }

    // n must be odd at this point. So we can skip
    // one element (Note i = i +2)
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        // While i divides n, print i and divide n
        if(n%i == 0) {
            int count = 0;
            while (n % i == 0) {
                count++;
                n = n/i;
            }
            factors.pb(mp(i, count));
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        factors.pb(mp(n, 1));
}

int lcm(int a, int b) {
    return (a*b)/(__gcd(a, b));
}

// number of power of v in n!
int get(int n, int v) {

    int cur = v,res = 0;

    while (cur <= n) {
        res += n / cur;
        if (cur > n / v)
            break;
        cur *= v;
    }

    return res;
}

// --------------------------template ends here------------------------------

void solve() {

    int t;
    // cin >> t;
    t = 1;

    while(t--) {

        int n;
        cin >> n;

        vector <int> v(n);

        for(auto &it : v)
            cin >> it;

        string ans = "";

        for(int i=0;i<n-1;i++) {
            int req = v[i];
            if(req > 0) {
                while(req > 0) {
                    req--;
                    ans += 'P';
                    ans += 'R';
                    if(req == 0)
                        break;
                    ans += 'L';

                }
            }
            else
                ans += 'R';
        }

        int req = v[n-1];
        if(req > 0) {
            while(req > 0) {
                req--;
                ans += 'P';
                ans += 'L';
                if(req == 0)
                    break;
                ans += 'R';

            }
        }
        else
            ans += 'L';

        cout << ans << endl;

    }

    return;
}

int32_t main() {

    FO;

    auto start = std::chrono::high_resolution_clock::now();

    solve();

    auto finish = std::chrono::high_resolution_clock::now();
    std::chrono::duration<double> elapsed = finish - start;
    cerr << "Elapsed time: " << elapsed.count() << " s\n";

}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        sum += arr[i];
    }
    string ans = "";
    for(int i=0;i<n;i++){
        int j=0;
        for(j=0;j<n-1;j++){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'R';
        }
        for(j=n-1;j>0;j--){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'L';
        }
        if(arr[0]>0){
            ans += 'P';
            sum--;
            if(sum==0){
                    cout << ans;
                    return 0;
            }
            arr[0]--;
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        sum += arr[i];
    }
    string ans = "";
    while(sum>0){
        int j=0;
        for(j=0;j<n-1;j++){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'R';
        }
        for(j=n-1;j>0;j--){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'L';
        }
    }
    cout << ans;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int arr[n];
    int sum=0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
        sum += arr[i];
    }
    string ans = "";
    for(int i=0;i<n;i++){
        int j=0;
        for(j=0;j<n-1;j++){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'R';
        }
        for(j=n-1;j>0;j--){
            if(arr[j] != 0){
                ans += 'P';
                sum--;
                if(sum==0){
                    cout << ans;
                    return 0;
                }
                arr[j]--;
            }
            ans += 'L';
        }
    }
    cout << ans;
    return 0;
}


/*
    In the name of Allah

    MohammadErfan Gooneh

*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++){ cout << a[i] ; if( i != n-1 )cout << ' ' ; };
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define get(a, n)                   for (int i = 0; i < n; i++) cin >> a[i] ;
#define vget(a, n)                  for(int i = 0 ; i < n ; i++){int tem ; cin >> tem ; a.push_back(tem) ; }
#define sget(a, n)                  for(int i = 0 ; i < n ; i++){int tem ; cin >> tem ; a.insert(tem) ; }
#define copy(a , b , n)             for(int i = 0 ; i < n ; i++)b[i]=a[i] ;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;

int main(){
    IOS ;
    int n ;
    cin >> n ;
    int a[n] ;
    get(a , n) ;
    bool check = 0 ;
    for(int i = 0 ; i < n ; i++){
        if(a[i] > 0){
            while(a[i]){
                if(i == 0){
                    cout << "PRL" ;
                    a[i]-- ;
                }
                else{
                    cout << "PLR" ;
                    a[i]-- ;
                }
            }
        }
        if(i!=n-1)cout << 'R' ;
    }

return 0 ;
}


#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];

for(int i=0; i<n; i++)
{
    cin>>arr[i];
}

for(int i=0; i<n; i++)
{
    while(arr[i]!=0)
    {
        cout<<"P";
        arr[i]--;
        if(arr[i]!=0)
            cout<<"LR";
        //if(arr[i]!=0&&i==n-1)
          //  cout<<""
    }

    if(arr[i]==0&&i!=n-1)
        cout<<"R";
}

}


#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
using namespace std;
int main()
{
int n;
cin>>n;
int arr[n];

for(int i=0; i<n; i++)
{
    cin>>arr[i];
}

for(int i=0; i<n; i++)
{
    while(arr[i]!=0)
    {
        cout<<"P";
        arr[i]--;
        if(arr[i]!=0&&i!=0)
            cout<<"LR";
        if(arr[i]!=0&&i==0)
        {
           cout<<"RL";
        }
        //if(arr[i]!=0&&i==n-1)
          //  cout<<""
    }

    if(arr[i]==0&&i!=n-1)
        cout<<"R";
}

}


#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,num,i,j;
  cin>>n;
  for(i=0;i<n-1;i++){
    cin>>num;
    for(j=0;j<num;j++){
      cout<<"PRL";
    }
    cout<<"R";
  }
  cin>>num;
  for(j=0;j<num;j++){
    cout<<"PLR";
  }

}


#include <bits/stdc++.h>
#define br  break
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define un   unsigned
#define do   double
#define cr   char
#define st   string
#define sc   scanf
#define pr   printf
#define mk   make_pair
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define vec  vector
#define gcd  __gcd
#define pi   acos( -1 )
#define ll   long long
#define N    200005
#define M    1000000007
#define I    1000000000000000000
#define en                 printf( "\n" )
#define sqr( a )           ( ( a ) * ( a ) )
#define all( c )           ( c ).begin(), ( c ).end()
#define rev( c )           reverse( all( c ) )
#define srt( c )           sort( all( c ) )
#define mxx( x, y, z )     max( x, max( y, z ) )
#define mnn( x, y, z )     min( x, min( y, z ) )
#define mxn( x, y, z )     max( x, min( y, z ) )
#define mnx( x, y, z )     min( x, max( y, z ) )
#define dist( x, y, z, c ) sqrt( sqr( x - z ) + sqr( y - c ) )
#define speed              ios_base::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 )
using namespace std;

ll n, a;
int main()
{
    cin >> n;
    for( int i = 1; i <= n; i ++ )
    {
        cin >> a;
        if( i == n )
            while( a -- )cout << "PLR";
        else
        {
            while( a -- )cout << "PRL";
            cout << "R";
        }
    }
}


#include <bits/stdc++.h>
#define br  break
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define un   unsigned
#define do   double
#define cr   char
#define st   string
#define sc   scanf
#define pr   printf
#define mk   make_pair
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define vec  vector
#define gcd  __gcd
#define pi   acos( -1 )
#define ll   long long
#define N    200005
#define M    1000000007
#define I    1000000000000000000
#define en                 printf( "\n" )
#define sqr( a )           ( ( a ) * ( a ) )
#define all( c )           ( c ).begin(), ( c ).end()
#define rev( c )           reverse( all( c ) )
#define srt( c )           sort( all( c ) )
#define mxx( x, y, z )     max( x, max( y, z ) )
#define mnn( x, y, z )     min( x, min( y, z ) )
#define mxn( x, y, z )     max( x, min( y, z ) )
#define mnx( x, y, z )     min( x, max( y, z ) )
#define dist( x, y, z, c ) sqrt( sqr( x - z ) + sqr( y - c ) )
#define speed              ios_base::sync_with_stdio( 0 ), cin.tie( 0 ), cout.tie( 0 )
using namespace std;

ll n, a;
int main()
{
    cin >> n;
    for( int i = 1; i <= n; i ++ )cin >> a;
    while( n -- )cout << "PR";
}


/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define mod ((long long)(1e9+7))

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	//ll t; cin>>t; while(t--){}
    ll n;
    cin>>n;
    vector<int> a(n);
    ll sum = 0;
    for(auto &i : a) {
    	cin>>i;
    	sum += i;
    }

    while(sum){
    	for(int i = 0; i < n; ++i){
    		if(a[i] > 0){
    			cout<<"P";
    			a[i]--;
    			sum--;
    		}
    		if(i != n-1) cout<<"R";
    	}
    	for(int i = 1; i < n; ++i)
    		cout<<"L";
    }
	return 0;
}


/**********************************************
* AUTHOR : Subhrangshu Pandey
* INSTITUTION : HIT, Kolkata
**********************************************/
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define mod ((long long)(1e9+7))

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

	//ll t; cin>>t; while(t--){}
    ll n;
    cin>>n;
    vector<int> a(n);
    for(auto &i : a) cin>>i;

    for(int i = 0; i < n; ++i){
    	if(a[i] > 0){
    		while(a[i]--)
    			cout<<"P";
    	}
    	if(i != n-1) cout<<"R";
    }
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int n, mx;
int a[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
int q = 1;
// cin >> q;
while (q--){
    cin >> n;
    ForE(i, 1, n){
        cin >> a[i];
        mx = max(mx, a[i]);
    }
    ForE(i, 1, mx){
        For(j, 1, n){
            if (i & 1){
                if (a[j] >= i) cout << 'P';
                cout << 'R';
            }
            else{
                if (a[n + 1 - j] >= i) cout << 'P';
                cout << 'L';
            }
        }
        if (i & 1){
            if (a[n] >= i) cout << 'P';
            cout << "LR";
        }
        else{
            if (a[1] >= i) cout << 'P';
            cout << "RL";
        }
    }
}
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/


#include<bits/stdc++.h>
using namespace std;

// Optimization

//#pragma GCC optimize("O3")
#define endl '\n'

// Shortcut

#define int long long
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)

// I/O & Debug

#define PrintV(a) Fora(iiii, a) cout << iiii << ' '; cout << endl;
#define PrintVl(a) Fora(iiii, a) cout << iiii << endl;
#define PrintA(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << ' '; cout << endl;
#define PrintAl(a, l, r) for (int iiii = l; iiii <= r; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/

// Functions

#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u' || a == 'y')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a))
#define mset1(a) memset(a, 1, sizeof(a))
#define msetn1(a) memset(a, -1, sizeof(a))
#define msetinf(a) memset(a, 0x3f, sizeof(a))
#define gcd __gcd
#define __builtin_popcount __builtin_popcountll
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());

// Data Structure

#define pque priority_queue
#define mts multiset
#define y0 _y0_
#define y1 _y1_
#define div divi
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;

const int N = 1e5 + 5, mod = 1e9 + 7, mod1 = 998244353, mod2 = 1e9 + 9, inf = 1e18 + 7;
const ll infll = 1e18 + 7;

int n;
int a[N];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
int q = 1;
// cin >> q;
while (q--){
    cin >> n;
    ForE(i, 1, n){
        cin >> a[i];
    }
    For(i, 1, 300){
        For(j, 1, n){
            if (i & 1){
                if (a[j] >= i) cout << 'P';
                cout << 'R';
            }
            else{
                if (a[n + 1 - j] >= i) cout << 'P';
                cout << 'L';
            }
        }
        if (i & 1){
            if (a[n] >= i) cout << 'P';
        }
        else{
            if (a[1] >= i) cout << 'P';
        }
    }
}
}

/*
==================================+
INPUT:                            |
------------------------------    |

------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |

------------------------------    |
==================================+
*/