#include<bits/stdc++.h>
using namespace std;
map<int, int>mp;
map<int, int>mp2;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n, t;
cin >> n >> t;
for (int i = 1; i <= n; i++) {
int a;
cin >> a;
mp[i] = a;
mp2[i] = i;
}
while (t--) {
int k;
cin >> k;
int pos = 1;
map<int, int>mp3 = mp2;
for (int i = 1; i <= k; i++) {
for (int j = 0; j * k + i <= n; j++) {
int p = j * k + i;
mp2[pos] = mp3[p];
pos++;
}
}
}
for (int i = 1; i <= n; i++) {
cout << mp[mp2[i]] << " ";
}
return 0;
}