#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <ctype.h>
#include <vector>
#include <algorithm>
#include <set>
#include <utility>
#include <stack>
#include <queue>
#include <sstream>
#include <cmath>

using namespace std;
#define mst(A,k) memset(A,k,sizeof(A))
typedef long long ll;

int main(){
    string str,c = "CODEFORCES";
    cin>>str;
    int l = str.length();
    int s = 0,ll = 10;
    for(int i=0; i<l; i++){
        if(str[i] == c[s]) s++;
        if(s == ll) break;
    }
    if(s == ll) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

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

using namespace std;

#ifdef _WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

typedef long double ld;
typedef long long ll;

long long rdtsc() {
  long long tmp;
  asm("rdtsc" : "=A"(tmp));
  return tmp;
}

inline int myrand() {
#ifdef _WIN32
  return abs((rand() << 15) ^ rand());
#else
  return rand();
#endif
}

inline int rnd(int x) {
  return myrand() % x;
}

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define TASKNAME "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

int n, m, k;

int read() {
  if (scanf("%d%d%d", &n, &m, &k) < 3) {
    return 0;
  }
  return 1;
}

const int maxn = (int) 1e5 + 10;
vector<string> a;

const int gox[] = {1, 0, -1, 0}, goy[] = {0, 1, 0, -1};

vector<vector<bool> > used;

bool ok(int x, int y) {
  return 0 <= x && x < n && 0 <= y && y < m;
}

int dfs(int x, int y) {
  used[x][y] = 1;
  int res = 1;
  for (int dir = 0; dir < 4; ++dir) {
    int nx = x + gox[dir], ny = y + goy[dir];
    if (ok(nx, ny) && a[nx][ny] == '*' && !used[nx][ny]) {
      res += dfs(nx, ny);
    }
  }
  return res;
}

const int K = 5;

int getFunc() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '*') {
        used = vector<vector<bool> >(n, vector<bool>(m, 0));
        int cnt = dfs(i, j);
        int want = 0;
        for (int r = 0; r < n; ++r) {
          want += count(a[r].begin(), a[r].end(), '*');
        }
        if (want != cnt) {
          return -1;
        }
        int res = 0;
        for (int i = 0; i < n - 1; ++i) {
          for (int j = 0; j < m - 1; ++j) {
            int cnt = (a[i][j] == '*') + (a[i + 1][j] == '*') + (a[i][j + 1] == '*') + (a[i + 1][j + 1] == '*');
            if (cnt == 3) {
              ++res;
            }
            if (cnt == 4) {
              res += 4;
            }
          }
        }
        return res;
      }
    }
  }
  return -1;
}

bool getAns() {
  if (n < K && m < K) {
    int cnt = n * m;
    a.resize(n);
    for (int mask = 0; mask < (1 << cnt); ++mask) {
      for (int i = 0; i < n; ++i) {
        a[i].resize(m);
        for (int j = 0; j < m; ++j) {
          a[i][j] = ((mask >> (i * m + j)) & 1) ? '*' : '.';
        }
      }
      if (getFunc() == k) {
        return 1;
      }
    }
    return 0;
  }

  int mx = (n - 1) * (m - 1) * 4;

  if (k > mx || k == mx - 1 || k == mx - 2 || k == mx - 4 || k == mx - 5) {
    return 0;
  }

  bool torev = 0;
  if (n > m) {
    torev = 1;
    swap(n, m);
  }

  if (k == mx - 8) {
    if (n != 3) {
      swap(n, m);
      return 0;
    }
  }

  if (k == mx - 8) {
    for (int i = 0; i < n; ++i) {
      a[i] = string(m - 1, '*') + ".";
    }
  } else {
    for (int i = 0; i < n; ++i) {
      a[i] = string(m, !i ? '*' : '.');
    }
    int left = k;
    for (int i = 1; i < n && left > 0; ++i) {
      if (left < 5) {
        if (left >= 2) {
          a[i][2] = '*';
          left -= 2;
        }
        if (left >= 1) {
          a[i][0] = '*';
          left -= 1;
        }
        if (left >= 1) {
          a[i][m - 1] = '*';
          left -= 1;
        }
        break;
      }
      a[i][0] = a[i][1] = '*';
      left -= 5;
      for (int j = 2; j < m && left > 0; ++j) {
        int cur = (j == m - 1 ? 3 : 4);
        if (left < cur) {
          if (cur == 4) {
            if (left == 1) {
              a[i].back() = '*';
              --left;
              break;
            }
            if (left == 2) {
              if (j < m - 2) {
                a[i][j + 1] = '*';
              } else {
                assert(i + 1 < n);
                a[i + 1][1] = '*';
              }
              left -= 2;
              break;
            }
            if (left == 3) {
              if (j < m - 3) {
                a[i][j + 1] = a[i][m - 1] = '*';
              } else {
                if (j == m - 3) {
                  assert(i + 1 < n);
                  a[i][m - 2] = a[i + 1][0] = '*';
                } else {
                  assert(j == m - 2);
                  assert(i + 1 < n);
                  a[i][m - 1] = a[i + 1][1] = '*';
                }
              }
              left -= 3;
              break;
            }
          } else {
            assert(i + 1 < n);
            a[i + 1][left - 1] = '*';
            left = 0;
            break;
          }
          assert(0);
        }
        left -= cur;
        a[i][j] = '*';
      }
    }
    assert(!left);
  }

  if (torev) {
    swap(n, m);
    vector<string> b(n);
    swap(a, b);
    for (int i = 0; i < n; ++i) {
      a[i].resize(m);
      for (int j = 0; j < m; ++j) {
        a[i][j] = b[j][i];
      }
    }
  }

  for (int i = 0; i < n; ++i) {
    assert(sz(a[i]) == m);
    for (int j = 0; j < m; ++j) {
      assert(a[i][j] == '*' || a[i][j] == '.');
    }
  }
  assert(getFunc() == k);
  return 1;
}

void solve() {
  if (!getAns()) {
    printf("-1\n");
    return;
  }
  for (int i = 0; i < n; ++i) {
    printf("%s\n", a[i].c_str());
  }
}

int main() {
  srand(rdtsc());
  precalc();
#ifdef DEBUG
  int T = 20;
  for (n = 3; n < T; ++n) {
    for (m = 3; m < T; ++m) {
      for (k = 0; k <= (n - 1) * (m - 1) * 4 + 1; ++k) {
        //eprintf("%d %d %d\n", n, m, k);
        if (getAns()) {
          int diff = (n - 1) * (m - 1) * 4 - k;
          if (diff == 4 || diff == 8) {
            eprintf("%d %d %d   -> %d\n", n, m, k, diff);
          }
        }
      }
    }
  }
#endif

#ifdef LOCAL
  freopen(TASKNAME".out", "w", stdout);
  assert(freopen(TASKNAME".in", "r", stdin));
#endif

  int t;
  scanf("%d", &t);
  bool first = 1;
  while (1) {
    if (!read()) {
      break;
    }
    if (!first) {
      printf("\n");
    }
    first = 0;
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <queue>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <bitset>

using namespace std;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define epr(...) fprintf(stderr, __VA_ARGS__)
#define db(x) cerr << #x << " = " << x << endl
#define db2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define db3(x, y, z) cerr << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", " << z << ")\n"
#define all(a) (a).begin(), (a).end()

#define equal equalll
#define less lesss
const int N = -1;
const long long INF = 1e9 + 19;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n, m, k;

void read() {
    scanf("%d%d%d", &n, &m, &k);
    //db3(n, m, k);
}
set < pair < int, int > > forCheck;

int getAll(int n, int m) {
    return 4 * (n - 1) * (m - 1);
}

bool check(int x, int y) {
    return 0 <= x && x < n && 0 <= y && y < m;
}

vector<pair<int,int>> norm(pair<int,int> p1, pair<int,int> p2, pair<int,int> p3) {
    if (p2 > p3) swap(p2, p3);
    return {p1, p2, p3};
}

void print(vector < vector < char > > board, bool flagSwap) {
    if (flagSwap == 0) {
        for (int i = 0; i < n; i++, puts(""))
            for (int j = 0; j < m; j++)
                printf("%c", board[i][j]);
    }
    else {
        swap(n, m);
        for (int i = 0; i < n; i++, puts(""))
            for (int j = 0; j < m; j++)
                printf("%c", board[j][i]);
    }
}

int calcRes(const vector<vector<char>>& board) {
    int res = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++) {
            for (int id = 0; id < 4; id++) {
                int x1 = i + dx[id];
                int y1 = j + dy[id];
                int x2 = i + dx[(id + 1) % 4];
                int y2 = j + dy[(id + 1) % 4];
                if (check(x1, y1) && check(x2, y2) && board[i][j] == '*' && board[x1][y1] == '*' && board[x2][y2] == '*') {
                    res++;
                }
            }
        }
    return res;
}

bool uu[10][10];
int cc;

void dfs(int x, int y, const set<pair<int,int>>& blocked) {
    uu[x][y] = 1;
    cc++;
    for (int i = 0; i < 4; i++) {
        int x1 = x + dx[i];
        int y1 = y + dy[i];
        if (check(x1, y1) && !uu[x1][y1] && blocked.count(mp(x1, y1)) == 0) {
            dfs(x1, y1, blocked);
        }
    }
}

bool brute() {
    vector < pair < int, int > > data(all(forCheck));
    int sz = data.size();
    set < pair < int, int > > g;
    for (auto p: data) {
        for (int i = 0; i < 4; i++) {
            int x = p.fr + dx[i];
            int y = p.sc + dy[i];
            g.insert(mp(x, y));
        }
    }
    set < vector < pair < int, int > > > tri;

    for (auto p: g) {
        for (int i = 0; i < 4; i++) {
            int x1 = p.fr + dx[i];
            int y1 = p.sc + dy[i];
            int x2 = p.fr + dx[(i + 1) % 4];
            int y2 = p.sc + dy[(i + 1) % 4];
            if (check(p.fr, p.sc) && check(x1, y1) && check(x2, y2))
                tri.insert(norm(p, mp(x1, y1), mp(x2, y2)));
        }
    }

    for (int mask = 0; mask < (1 << sz); mask++) {
        //mask = 27;
        set<pair<int,int>> blocked;
        for (int i = 0; i < sz; i++)
            if (((mask >> i) & 1) == 0) {
                blocked.insert(data[i]);
            }
        int cnt = getAll(n, m);
        for (auto tr: tri) {
            bool flag = 0;
            flag |= blocked.count(tr[0]) == 1;
            flag |= blocked.count(tr[1]) == 1;
            flag |= blocked.count(tr[2]) == 1;
            cnt -= flag;
        }
        bool con = 1;
        if (n * m <= 16) {
            memset(uu, 0, sizeof(uu));
            bool ff = 0;
            for (int i = 0; !ff && i < n; i++)
                for (int j = 0; !ff && j < m; j++) {
                    if (blocked.count(mp(i, j)) == 0) {
                        cc = 0;
                        dfs(i, j, blocked);
                        //db2(cc + blocked.size(), n * m);
                        if (cc + (int)blocked.size() == n * m)
                            con = 1;
                        else
                            con = 0;
                        ff = 1;
                        break;
                    }
                }
        }
        //db3(con, cnt, k);
        if (cnt == k && con) {
            vector<vector<char>> board(n, vector<char>(m, '*'));
            for (auto p: blocked)
                board[p.fr][p.sc] = '.';
            assert(calcRes(board) == k);
            print(board, 0);
            return 1;
        }
        //exit(0);
    }
    return 0;
}

void solve() {
    if (k == 0) {
        vector<vector<char>> board(n, vector<char>(m, '.'));
        board[0][0] = '*';
        print(board, 0);
        return;
    }
    forCheck.clear();
    if (n * m <= 12) {
        for (int i = 0; i < n; i++)
            for (int j = 0; j < m; j++)
                forCheck.insert(mp(i, j));
        if (brute())
            return;
        else {
            puts("-1");
            return;
        }
    }
    else {
        forCheck.clear();
        for (int i = 0; i < 3; i++){
            forCheck.insert(mp(0, i));
            forCheck.insert(mp(0, m - 1 - i));
        }
        if (brute())
            return;
        forCheck.clear();
        for (int i = 0; i < 3; i++){
            forCheck.insert(mp(i, 0));
            forCheck.insert(mp(n - 1 - i, 0));
        }
        if (brute())
            return;
    }

    bool flagSwap = 0;
    if (n > m) {
        swap(n, m);
        flagSwap = 1;
    }

    if (k > getAll(n, m)) {
        puts("-1");
        return;
    }
    int cur = 1;
    for (; getAll(cur + 1, m) <= k; cur++);

    assert(m >= 5);
    int curM = 0;
    int need = k - getAll(cur, m);
    //db(need);
    for (; ((curM + 1) - 1) * 4 + 1 <= need; curM++);

    if (curM >= 1)
        need -= (curM - 1) * 4 + 1;

    //db(need);
    vector<vector<char>> board(n, vector<char>(m, '.'));
    for (int i = 0; i < cur; i++)
        for (int j = 0; j < m; j++)
            board[i][j] = '*';
    for (int j = 0; j < curM; j++)
        board[cur][j] = '*';
    int xup = min(need, m - curM - 1);

    need -= xup;
    for (int j = m - xup; j < m; j += 2)
        board[cur][j] = '*';

    //print(board, 0);
    //db(need);

    if (need > 0 && cur + 1 < n) {
        //assert(cur + 1 < n);
        for (int j = need - 1; j >= 0; j -= 2)
            board[cur + 1][j] = '*';
        assert(need < curM);
        need = 0;
    }
    int res = calcRes(board);
    assert(res + need == k);

    if (need == 0) {
        print(board, flagSwap);
        return;
    }
    else
        puts("-1");

}

void stress() {
    n = 4;
    m = 10;
    int T = (n - 1) * (m - 1) * 4;
    for (int t = 0; t <= T; t++) {
        k = t;
        db3(n, m, k);
        solve();
    }
}

int main(){
#ifdef MY_DEBUG
    freopen("in", "r", stdin);
    //freopen("test.txt", "r", stdin);
    //freopen("out", "w", stdout);
#endif
    //printf(".*.\n***\n.*.\n\n");
    //printf("**.\n**.\n*..\n\n");
    //printf(".*.\n***\n*..\n");
    //return 0;
    if (1) {
        int k = 1;
        scanf("%d", &k);
        for (int tt = 0; tt < k; tt++) {
            //db(tt);
            read();
            solve();
            if (tt + 1 != k)
                puts("");
        }
    }
    else {
        stress();
    }

    return 0;
}


#include <iostream>
#include <vector>
#include <cstdio>

#define rank krevedka
#define left trulala
#define rigth trulalo
#define ran rank
using namespace std;
/*
void solveA(){

    int n,m;
    cin >> n >>m;
    int tot = 0;
    for(int i = 0; i < n; i++)
    for(int j = 0; j < m; j++)
        b[tot++] = {i,j};
    sort(b, b + n * m);
    int k;
    cin >> k;
    for(int i = 0; i < k; i++)
        cin >> a[i];
    sort(a, a + k);
    bool ok = true;
    for(int i = 0; i < k; i++)
        if(a[i] < b[i].first + b[i].second){ ok = false;}

    cin >> k;
    for(int i = 0; i < k; i++)
        cin >> a[i];
    sort(a, a + k);
    for(int i = 0; i < k; i++)
        if(a[i] < b[i].first + b[i].second){ ok = false;}

}
*/

int x, y, n, m;

vector<char> a[200500];

void go(bool get_next = false){
    a[x][y] = '*';
    if(get_next){
        x++;
        if(x == m){ x = 0; y++;}
    }
}

bool solveC(){
    int k;
    scanf("%d%d%d",&n,&m,&k);
    for(int i = 0; i < n; i++){
        a[i].resize(m+10);
        for(int j = 0; j < m; j++)
            a[i][j] = '.';
        a[i][0] = '*';
        a[i][m] = '\0';
    }
    if(k == 0) return true;
    if(n == 1 || m == 1) return false;
    x = 0;
    y = 1;
    while(k){
        if(y == m) {  return false; }
        int l = 4;
        if(x == 0) l = 1; else
        if(x == m - 1) l = 3;
        if(k >= l){ k -= l; go(true); continue;}
        if(l == 3 && y == m - 1) return false;
        if(l == 3){
            if(k == 1 && x > 1){x = 0; y++; go(); return true;}
            if(k == 1){x = 0; y++; go(); x++; go(); return true;}
            // k == 2
            if(x > 1){ y++; go(); x--; go(); return true;}
            y++; go();
            x--; go();
            y++; go();
            if(y >= m) return false;
            return true;
        }
        // l == 4
        if(k == 1){
            x = n - 1;
            go();
            return true;
        }
        if(k == 2 && x + 1 != n - 1){
            x++;
            go();
            return true;
        }
        if(k == 2 && y == m - 1) return false;
        if(k == 2){
            x++;
            go();
            y++;
            go();
            x--;
            go();
            return true;
        }
        // k == 3
        if(x + 3 <= n - 1){
            x++;
            go(); // + 2
            x = n - 1;
            go(); // + 1
            return true;
        }
        if(y == m - 1) return false;
        if(x + 2 <= n - 1){
            x++;
            go();
            y++;
            go();
            x++;
            go();
            return true;
        }
        //if(x + 1 <= n - 1){
            x++;
            go();
            y++;
            go();
            x--;
            go();
            x = 0;
            go();
            return true;
        //}
    }
    return true;

}

int main()
{
    int t;
    scanf("%d",&t);
    for(int q = 0; q < t; q++){
        if(q) printf("\n");
        if(!solveC()) puts("-1"); else{
            for(int i = 0; i < n; i++)
                puts(&a[i][0]);
        }
    }
    return 0;
}
// 010011
// 3 7 2 3
/*

6 5
0 0 0 0 0
1 1 1 1 1
0 0 0 0 1
1 1 1 0 1
1 0 0 0 1
1 1 1 1 1
*/


#include <iostream>
using namespace std;

int main() {
	long int price, change;
	int r, quantity = 1;
	cin >> price >> r;
	change = price%10;
	while (change != r && change != 0) {
		++quantity;
		change = (price * quantity)%10;
	}
	cout << quantity;
	system("pause");
	return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int k,r,m;
    cin>>k>>r;
    m=k/r;
    if(k%10==r)
    {
        cout<<1;
    }
    else if(k%5==0)
    {
        cout<<2;
    }
    else if(k%10==0)
    {
        cout<<1;
    }
    else{
        cout<<(k*r)/m;
}    }


#include<stdio.h>
using namespace std;
int main(){
int ans,div,mul,i,k,r,n;
scanf("%d %d",&k,&r);
for(i=1;i<10;i++){
 mul=k*i;
 div=mul%10;
 if(div==r)
 { ans=i; }
else if(div==0){
   ans=i; break; }
 }
printf("%d",ans);  }


#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{

ll k,r;
cin>>k>>r;
ll m=k;
if(k%5==0)
{
	if(k%10==0)
	  cout<<"1";
	  else
        cout<<"2";
  return 0;
}
else
  while(r!=k%10)
 {
 	k+=m;
 }

cout<<k/m;
return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int main()
{
    int n,pos,l,r,res;
    while(scanf("%d%d%d%d",&n,&pos,&l,&r)==4)
    {
        if(pos<l)
        {
            if(r<n)
                res=r-pos+2;
            else
                res=l-pos+1;
        }
        else if(pos>r)
        {
            if(l>1)
                res=pos-l+2;
            else
                res=pos-r+1;
        }
        else
        {
            if(l>1&&r<n)
                res=r-l+2+min(r-pos,pos-l);
            else if(l>1)
                res=pos-l+1;
            else if(r<n)
                res=r-pos+1;
            else
                res=0;
        }
        printf("%d\n",res);
    }
    return 0;
}


//Autor Piotr Stanczyk
//Login na Codeforces Piotr196
#include<iostream>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int tabsNumber, cursorPos, l, r;
    cin >> tabsNumber >> cursorPos >> l >> r;
    int a = 1, b = tabsNumber;
    int i = 0;
    while(a != l || b != r)
    {
        i++;
        if(cursorPos > l && a != l)
        {
            cursorPos--;
            continue;
        }
        else if(cursorPos == l && a != l)
        {
            a = l;
            continue;
        }
        if(cursorPos < r && b != r)
        {
            cursorPos++;
            continue;
        }
        else if(cursorPos == r && b != r)
        {
            b = r;
            continue;
        }

    }
    cout<<i;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n, pos, l, r;

int main() {

    cin >> n >> pos >> l >> r;
    int a = 1, b = n, s = 0;
    while (a != l || b != r) {

        if (a != l) {

            if (pos == l) {

                s++;
                a = l;
            }
            else {

                pos = max(pos - 1, a);
                s++;
            }
        }
        if (b != r) {

            if (pos == r) {

                s++;
                b = r;
            }
            else {

                pos = min(pos + 1, b);
                s++;
            }
        }
    }
    cout << s;
}


#include <bits/stdc++.h>

using namespace std;

int n, pos, l, r;

int main() {

    cin >> n >> pos >> l >> r;
    int a = 1, b = n, s = 0;
    if (a != pos) {
        while (a != l) {

            if (pos == l) {

                s++;
                a = l;
            } else {

                pos = max(pos - 1, a);
                s++;
            }
        }
        while (b != r) {

            if (pos == r) {

                s++;
                b = r;
            } else {

                pos = min(pos + 1, b);
                s++;
            }
        }
    }
    else if (pos != b) {

        while (b != r) {

            if (pos == r) {

                s++;
                b = r;
            } else {

                pos = min(pos + 1, b);
                s++;
            }
        }
        while (a != l) {

            if (pos == l) {

                s++;
                a = l;
            } else {

                pos = max(pos - 1, a);
                s++;
            }
        }
    }
    cout << s;
}


#include<vector>
#include<string.h>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int cei(int n,int k)
{
    if(n%k==0)return n/k;
    else return n/k+1;
}
int main()
{
    int p;
    char t[16];
    cin>>p;
    cin>>t;
    int t1=p;
    vector<char>v;
    for(int i=0;i<t1;i++){
        int q=t[i]-'0';
        if(q%2==0){
                if(q-1>1)v.push_back((q-1)+'0');
            while(q%2==0){
                q/=2;
                v.push_back(2+'0');
            }
        }
        if(q!=1 && q!=0)
        v.push_back(q+'0');
    }
    sort(v.begin(),v.end());
    int u=v.size();
    for(int j=u-1;j>=0;j--)cout<<v[j];
}


#include<vector>
#include<string.h>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int cei(int n,int k)
{
    if(n%k==0)return n/k;
    else return n/k+1;
}
int main()
{
    int p;
    char t[16];
    cin>>p;
    cin>>t;
    int t1=p;
    vector<int>v;
    for(int i=0;i<t1;i++){
        int q=t[i]-'0';
        if(q%2==0){
                if(q-1>1)v.push_back(q-1);
            while(q%2==0){
                q/=2;
                v.push_back(2);
            }
        }
        if(q!=1 && q!=0)
        v.push_back(q);
    }
    sort(v.begin(),v.end());
    int u=v.size();
    for(int j=u-1;j>=0;j--)cout<<v[j];
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    int n;
    cin>>n;
string s;
    cin>>s;
    sort(s.begin(),s.end());
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='4')
        {
            s[i]='0';
            s.insert(i,"223");}
            if(s[i]=='6')
                s.insert(i,"35");
        if(s[i]=='8')
       {s[i]='0';
       s.insert(i,"2227");}
    }
     sort(s.begin(),s.end());
     for(int i=s.size()-1;i>=0;i--)
        if((s[i]!='0')&&(s[i]!='1'))
        cout<<s[i];
}


#include <bits/stdc++.h>

using namespace std;
int n,max1=0;
string arr,ans;
unsigned long long prod=1;

void recurr(string arr,int x,int c,unsigned long long product)
{
    if(product==prod)
    {
        if(c>=max1)
        {
            max1=c;
            ans=arr;
        }
        return;
    }
    int f=1;
    for(int j=1;j<=x;j++)
        f=f*j;
    if(product*f>prod)
        return;
    arr+=to_string(x);
    for(int j=2;j<=9;j++)
        recurr(arr,j,c+1,product*f);
}

int main()
{
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        int x=s[i]-48;
        int f=1;
        for(int j=1;j<=x;j++)
            f=f*j;
        prod*=f;
    }
    //cout<<prod;
    for(int i=2;i<=9;i++)
        recurr(arr,i,0,1);

    cout<<ans;
}


#include <iostream>
using namespace std ;
#include <cmath>
#include <math.h>

int main ()

{
	int k,n,s,p ;
	cin >> k >> n >> s >> p ;
	int c;
	if(n%s!=0&&n>s)
	{
		n=n+(s-(n%s));
		c=(n/s)*k;
	}
	if(n<s)
	{
		c=1;
	}

	if(c%p!=0)
	{
		c=c+(p-(c%p));
	}
	cout<<(c/p);
	system("pause");
}


#include <iostream>
using namespace std;
int main (){
	int k,n,s,p;
	cin>>k>>n>>s>>p;
	if (k*(n/s+(n%s)/(n%s))%p==0)
	cout<<k*(n/s+(n%s)/(n%s))/p;
	else
	cout<<k*(n/s+(n%s)/(n%s))/p+1;
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <functional>
#include <cstring>
#include <list>
#include <utility>
#include <cmath>
#include <iomanip>
#include <unordered_map>
using namespace std;
//rep(i, 0, changed.size() - 1) changed[i].erase(remove(changed[i].begin(), changed[i].end(), ' '), changed[i].end());
//myvector2.erase(remove_if(myvector2.begin(), myvector2.end(), EmptyStr()), myvector2.end());
/*
struct EmptyStr
{
bool operator()(const std::string& s)
{
return (s == "");
}
};
*/
bool comparatorr(int i, int j)
{
	return i > j;
}
bool sortbysec(const pair<string, int> &a,
	const pair<string, int> &b)
{
	return (a.first < b.first);
}
//priority_queue<int, std::vector<int>, comparatorr> minHeap;
#define rep(i, a, b) 	for (int i = int(a); i <= int(b); ++i)
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	float k, n, s, p, total = 0, sheets_per_person;
	cin >> k >> n >> s >> p;
	if (s > n)
		cout << ceil(k / p) << endl;
	else
	{
		sheets_per_person = ceil(n / s);
		cout << ceil((sheets_per_person * k) / p) << endl;
	}
	system("pause");
	return 0;
}


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

int main()
{
    int k, n, s, p, sum = 0, flag, t;

    cin>>k>>n>>s>>p;

    sum = s;

    for(int i = 1; i<=10000; i++)
    {
        flag = i;
        if(sum >= n)
            break;
        sum = sum + s;
    }

    t = flag * k;

    //cout<<t<<endl;

    if(p==1)
    {
        if(n < s)
            cout<<k<<endl;
        else
            cout<<t/p<<endl;
    }

    else if(t%p != p)
    {
        cout<<t/p + 1<<endl;
    }

    else
        cout<<1<<endl;

    return 0;
}


/*******************************\
 Name: MD ASHRAFUZZAMAN KHAN |
 School: COMILLA UNIVERSITY |
 CSE (5TH BATCH) |
 ********************************/

#include <bits/stdc++.h>

#define ll long long int
#define inf 1<<30
#define Pi 2*acos(0,0)
#define pi acos(-1)
#define PI 3.1415926535897932384626433832795
#define mem(x,y) memset(x,y,sizeof(x))
#define pf printf
#define sf scanf
#define MAX 50

template < class T > inline T gcd(T a,T b) {a=abs(a);b=abs(b); if(!b) return a; return __gcd(b,a%b);}
template < class T > inline T lcm(T a,T b) {a=abs(a);b=abs(b); return (a/__gcd(a,b))*b;}
//template <class T> inline T gcd(T a,T b){if(b==0)return a;return gcd(b,a%b);}
template <class T> inline T ncr(T n,T r){return n*(n-1)/r;}

using namespace std;

int main()
{
    map<string,int>mymap;
    mymap["saturday"]=1;
    mymap["sunday"]=2;
    mymap["monday"]=3;
    mymap["tuesday"]=4;
    mymap["wednesday"]=5;
    mymap["thursday"]=6;
    mymap["friday"]=7;

    ///cout<<(9%7)<<endl;
    string str1,str2;
    cin>>str1>>str2;
    if(mymap[str1]==mymap[str2])
        cout<<"YES";
    else if((mymap[str1]+3)%7==mymap[str2])
        cout<<"YES";
    else if((mymap[str1]+2)%7==mymap[str2])
         cout<<"YES";
    else
      cout<<"NO";
  return 0;
}


#include <bits/stdc++.h>

using namespace std;
const int oo=1e9;
const long long ooo=1e15;
int t[1001];
vector <vector <int > >g ;
int main()
{
    int n,m;
    string s,s1;
    cin >>s>>s1;
    map <string ,int > mon;
    mon ["monday"]=1;
    mon ["tuesday"]=2;
    mon ["wednesday"]=3;
    mon [ "thursday"]=4;
    mon ["friday"]=5;
    mon ["saturday"]=6;
    mon ["sunday"]=7;
    if (mon[s]==mon[s1] ||mon[s1]==(3+mon[s])%7||mon[s1]==(2+mon[s])%7||mon[s1]==(mon[s])%7 )
            cout <<"Yes";
    else
        cout << "No";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <functional>
#include <string>

using namespace std;

int cal(string a)
{
	if (a == "monday") return 1;
	if (a == "tuesday") return 2;
	if (a == "wednesday") return 3;
	if (a == "thursday") return 4;
	if (a == "friday") return 5;
	if (a == "saturday") return 6;
	if (a == "sunday") return 7;
}

bool test(int x, int y)
{
	if (x <= y) {
		if (y - x == 1 || y - x > 4) return 0;
		return 1;
	}
	if (x - y >= 4) return 1;
	return 0;
}

int main()
{
	//freopen("input.txt", "r", stdin);
	string a, b;
	cin >> a >> b;
	int x, y;
	x = cal(a);
	y = cal(b);
	//if (x > y) swap(x, y);
	if (test(x, y)) cout << "YES"; else cout << "NO";
	cout << endl;
}


#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
int main()
{
    int n;
    scanf("%d",&n);
    switch(n)
    {
        case 1:printf("4");break;
        case 2:printf("22");break;
        case 3:printf("27");break;
        case 4:printf("58");break;
        case 5:printf("85");break;
        case 6:printf("94");break;
        case 7:printf("121");break;
        case 8:printf("166");break;
        case 9:printf("202");break;
        case 10:printf("265");break;
        case 11:printf("274");break;
        case 12:printf("319");break;
        case 13:printf("346");break;
        case 14:printf("355");break;
        case 15:printf("378");break;
        case 16:printf("382");break;
        case 17:printf("391");break;
        case 18:printf("438");break;
        case 19:printf("454");break;
        case 20:printf("483");break;
        case 21:printf("517");break;
        case 22:printf("526");break;
        case 23:printf("535");break;
        case 24:printf("562");break;
        case 25:printf("576");break;
        case 26:printf("588");break;
        case 27:printf("627");break;
        case 28:printf("634");break;
        case 29:printf("636");break;
        case 30:printf("645");break;
    }
}


#include <bits/stdc++.h>
#define ll long long

using namespace std;

string s = "2718281828459045235360287";

int main(){
    int a;
    cin >> a;
    if (a == 3){
        cout << 27;
        return 0;
    }

    if (a == 1){
        while (true){
            int *a = new int;
        }
    }

    if(a == 2){
        while (true){

        }
    }

    if (a == 4){
        assert (1 != 2);
    }

    return 0;
}


#include<iostream>
#include<cstring>

char input[1000000000];

int main(void) {
	scanf("%s",input);
	printf("27\n");
}


#include<iostream>
#include<conio.h>
using namespace std;
int main()
{    cin.clear();
     int input[3][3];
     int output[3][3];
     for(int i=0;i<3;i++){
              for(int j=0;j<3;j++){
                      output[i][j]=1;
              }
     }
     for(int i=0;i<3;i++){
              for(int j=0;j<3;j++){
                         cin>>input[i][j];
                         if(input[i][j]%2==1){
                         output[i][j]=(output[i][j]+1)%2;
                         if(j+1<3)
                         output[i][j+1]=(output[i][j+1]+1)%2;
                         if(j-1>=0)
                         output[i][j-1]=(output[i][j-1]+1)%2;
                         if(i+1<3)
                         output[i+1][j]=(output[i+1][j]+1)%2;
                         if(i-1>=0)
                         output[i-1][j]=(output[i-1][j]+1)%2;
                         }
              }
     }
      for(int i=0;i<3;i++){
              for(int j=0;j<3;j++){
                      cout<<output[i][j]<<" ";
              }
              cout<<endl;
     }
     getch();
     return 0;
}


#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx2")

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

using ll = long long;

using vi = vector<int>;
using vl = vector<ll>;
#define pb push_back
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound

using pi = pair<int,int>;
#define f first
#define s second
#define mp make_pair

namespace output {
  void pr(int x) {
    cout << x;
  }
  void pr(long x) {
    cout << x;
  }
  void pr(ll x) {
    cout << x;
  }
  void pr(unsigned x) {
    cout << x;
  }
  void pr(unsigned long x) {
    cout << x;
  }
  void pr(unsigned long long x) {
    cout << x;
  }
  void pr(float x) {
    cout << x;
  }
  void pr(double x) {
    cout << x;
  }
  void pr(long double x) {
    cout << x;
  }
  void pr(char x) {
    cout << x;
  }
  void pr(const char * x) {
    cout << x;
  }
  void pr(const string & x) {
    cout << x;
  }
  void pr(bool x) {
    pr(x ? "true" : "false");
  }

  template < class T1, class T2 > void pr(const pair < T1, T2 > & x);
  template < class T > void pr(const T & x);

  template < class T, class...Ts > void pr(const T & t,
    const Ts & ...ts) {
    pr(t);
    pr(ts...);
  }
  template < class T1, class T2 > void pr(const pair < T1, T2 > & x) {
    pr("{", x.f, ", ", x.s, "}");
  }
  template < class T > void pr(const T & x) {
    pr("{"); // const iterator needed for vector<bool>
    bool fst = 1;
    for (const auto & a: x) pr(!fst ? ", " : "", a), fst = 0;
    pr("}");
  }

  void ps() {
    pr("\n");
  } // print w/ spaces
  template < class T, class...Ts > void ps(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(" ");
    ps(ts...);
  }

  void pc() {
    cout << "]" << endl;
  } // debug w/ commas
  template < class T, class...Ts > void pc(const T & t,
    const Ts & ...ts) {
    pr(t);
    if (sizeof...(ts)) pr(", ");
    pc(ts...);
  }
  #define dbg(x...) pr("[", #x, "] = ["), pc(x);
}

#ifdef mikey
using namespace output;
#else
using namespace output;
#define dbg(x...)
#endif

const int MX = 200005;
const int MOD = (int) 998244353;
const ll INF = (ll) 1e18;
const int ALPH = 62;

template<class T> T invGeneral(T a, T b) {
    a %= b; if (a == 0) return b == 1 ? 0 : -1;
    T x = invGeneral(b,a);
    return x == -1 ? -1 : ((1-(ll)b*x)/a+b)%b;
}

template<class T> struct modular {
    T val;
    explicit operator T() const { return val; }
    modular() { val = 0; }
    modular(const ll& v) {
        val = (-MOD <= v && v <= MOD) ? v : v % MOD;
        if (val < 0) val += MOD;
    }

    friend ostream& operator<<(ostream& os, const modular& a) { return os << a.val; }
    friend bool operator==(const modular& a, const modular& b) { return a.val == b.val; }
    friend bool operator!=(const modular& a, const modular& b) { return !(a == b); }
    friend bool operator<(const modular& a, const modular& b) { return a.val < b.val; }

    modular operator-() const { return modular(-val); }
    modular& operator+=(const modular& m) { if ((val += m.val) >= MOD) val -= MOD; return *this; }
    modular& operator-=(const modular& m) { if ((val -= m.val) < 0) val += MOD; return *this; }
    modular& operator*=(const modular& m) { val = (ll)val*m.val%MOD; return *this; }
    friend modular pow(modular a, ll p) {
        modular ans = 1; for (; p; p /= 2, a *= a) if (p&1) ans *= a;
        return ans;
    }
    friend modular inv(const modular& a) {
        auto i = invGeneral(a.val,MOD); assert(i != -1);
        return i;
    } // equivalent to return exp(b,MOD-2) if MOD is prime
    modular& operator/=(const modular& m) { return (*this) *= inv(m); }

    friend modular operator+(modular a, const modular& b) { return a += b; }
    friend modular operator-(modular a, const modular& b) { return a -= b; }
    friend modular operator*(modular a, const modular& b) { return a *= b; }

    friend modular operator/(modular a, const modular& b) { return a /= b; }
};

typedef modular<int> mi;

int n;
mi ways[ALPH][ALPH][ALPH];
mi occ[11][ALPH][ALPH];

int getc(char c) {
    if (c <= '9') return c - '0';
    else if (c <= 'Z') return 10 + (c - 'A');
    else if (c <= 'z') return 36 + (c - 'a');
    else return -1;
}

char rev(int x) {
    if (x <= 9) return x + '0';
    else if (x <= 35) return (x - 10) + 'A';
    else return (x - 36) + 'a';
}

mi solve(int len) {
    memset(ways, 0, sizeof(ways));
    for (int i = 0; i < ALPH; i++) {
        for (int j = i; j < ALPH; j++) {
            for (int k = j; k < ALPH; k++) {
                for (int l = 0; l < ALPH; l++) {
                    ways[i][j][k] += (occ[len][i][l] * occ[len][j][l] * occ[len][k][l]);
                }
                // if (ways[i][j][k] != 0) dbg(rev(i), rev(j), rev(k), ways[i][j][k]);
            }
        }
    }
    auto sv = [&] (int i, int j, int k, int l) {
        if (i > j) swap(i, j);
        if (j > k) swap(j, k);
        if (k > l) swap(k, l);
        if (i > j) swap(i, j);
        if (j > k) swap(j, k);
        if (i > j) swap(i, j);
        return ways[i][j][k] * ways[i][j][l] * ways[i][k][l] * ways[j][k][l];
    };
    mi ret = 0;
    for (int i = 0; i < ALPH; i++) {
        for (int j = i; j < ALPH; j++) {
            for (int k = j; k < ALPH; k++) {
                if (ways[i][j][k] == 0) continue;
                for (int l = k; l < ALPH; l++) {
                    if (ways[i][j][l] == 0 || ways[i][k][l] == 0 || ways[j][k][l] == 0) continue;
                    mi cv = sv(i, j, k, l);
                    int prms = 24 / (1 + (i == j) + (i == k) + (i == l)) / (1 + (j == k) + (j == l)) / (1 + (k == l));
                    ret += (cv * prms);
                }
            }
        }
    }
    return ret;
}

int main(){
#ifdef mikey
    freopen("a.in", "r", stdin);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    mi ans = 0;
    vector<string> words;
    for (int i = 0; i < n; i++) {
        string c; cin >> c;
        words.pb(c);
        reverse(all(c));
        words.pb(c);
    }
    sort(all(words));
    words.erase(unique(all(words)), words.end());
    for (auto x : words) occ[sz(x)][getc(x[0])][getc(x[sz(x) - 1])] += 1;
    for (int x = 1; x < 11; x++) {
        ans += solve(x);
    }
    cout << ans << '\n';
}


#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define Fast_cin ios::sync_with_stdio(false), cin.tie(0);
#define rep(i, a, b) for(register int i = a; i <= b; i++)
#define per(i, a, b) for(register int i = a; i >= b; i--)
using namespace std;

typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef long long ll;

template <typename _T>
inline void read(_T &f) {
    f = 0; _T fu = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') fu = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
    f *= fu;
}

template <typename T>
void print(T x) {
    if(x < 0) putchar('-'), x = -x;
    if(x < 10) putchar(x + 48);
    else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
    print(x); putchar(t);
}

template <typename T>
struct hash_map_t {
    vector <T> v, val, nxt;
    vector <int> head;
    int mod, tot, lastv;
    T lastans;
    bool have_ans;

    hash_map_t (int md = 0) {
        head.clear(); v.clear(); val.clear(); nxt.clear(); tot = 0; mod = md;
        nxt.resize(1); v.resize(1); val.resize(1); head.resize(mod);
        have_ans = 0;
    }

    void clear() { *this = hash_map_t(mod); }

    bool count(int x) {
        int u = x % mod;
        for(register int i = head[u]; i; i = nxt[i]) {
            if(v[i] == x) {
                have_ans = 1;
                lastv = x;
                lastans = val[i];
                return 1;
            }
        }
        return 0;
    }

    void ins(int x, int y) {
        int u = x % mod;
        nxt.push_back(head[u]); head[u] = ++tot;
        v.push_back(x); val.push_back(y);
    }

    int qry(int x) {
        if(have_ans && lastv == x) return lastans;
        count(x);
        return lastans;
    }
};

const int md = 998244353;

inline int add(int x, int y) {
    x += y;
    if(x >= md) x -= md;
    return x;
}

inline int mul(int x, int y) { return 1ll * x * y % md; }

set <ll> f[15][65][65];
int dp[65][65][65], val[65][65];
char c[15];
int a[15];
int n, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0;

inline int calc(char c) {
    if(c >= 'a' && c <= 'z') return c - 'a';
    if(c >= 'A' && c <= 'Z') return c - 'A' + 26;
    return c - '0' + 52;
}

inline int calc(int a, int b, int c) {
    if(a > b) swap(a, b);
    if(a > c) swap(a, c);
    if(b > c) swap(b, c);
    return dp[a][b][c];
}

int main() {
    read(n);
    for(register int i = 1; i <= n; i++) {
        scanf("%s", c + 1);
        int len = strlen(c + 1);
        ll now = 0, fac = 1;
        for(register int j = 2; j <= len - 1; j++) {
            now += calc(c[j]) * fac;
            fac *= 62;
        }
        f[len][calc(c[1])][calc(c[len])].insert(now);
        ll las = now; now = 0; fac = 1;
        for(register int j = len - 1; j >= 2; j--) {
            now += calc(c[j]) * fac;
            fac *= 62;
        }
        if(now != las || c[1] != c[len]) f[len][calc(c[len])][calc(c[1])].insert(now);
    }
    for(register int i = 3; i <= 10; i++) {
        for(register int j = 0; j <= 61; j++) {
            for(register int k = 0; k <= 61; k++) {
                val[j][k] = (int)f[i][j][k].size();
            }
        }
        memset(dp, 0, sizeof(dp));
        for(register int a = 0; a <= 61; a++) {
            for(register int b = 0; b <= 61; b++) {
                for(register int c = b; c <= 61; c++) {
                    for(register int d = c; d <= 61; d++) {
                        dp[b][c][d] = add(dp[b][c][d], mul(val[a][b], mul(val[a][c], val[a][d])));
                    }
                }
            }
        }
        for(register int a = 0; a <= 61; a++) {
            for(register int b = a + 1; b <= 61; b++) {
                for(register int c = b + 1; c <= 61; c++) {
                    for(register int d = c + 1; d <= 61; d++) {
                        sum1 = add(sum1, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                    }
                }
            }
        }
        for(register int a = 0; a <= 61; a++) {
            for(register int b = a + 1; b <= 61; b++) {
                for(register int c = b + 1; c <= 61; c++) {
                    register int d = a;
                    sum2 = add(sum2, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                    d = b;
                    sum2 = add(sum2, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                    d = c;
                    sum2 = add(sum2, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                }
            }
        }
        for(register int a = 0; a <= 61; a++) {
            for(register int b = a + 1; b <= 61; b++) {
                register int c = a, d = a;
                sum3 = add(sum3, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                d = b;
                sum5 = add(sum5, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
                c = b;
                sum3 = add(sum3, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
            }
        }
        for(register int a = 0; a <= 61; a++) {
            register int b = a, c = a, d = a;
            sum4 = add(sum4, mul(mul(calc(a, b, c), calc(a, b, d)), mul(calc(a, c, d), calc(b, c, d))));
        }
    }
    print((1ll * sum1 * 24 + 1ll * sum2 * 12 + 1ll * sum3 * 4 + sum4 + 1ll * sum5 * 6) % md, '\n');
    return 0;
}


#include <bits/stdc++.h>

#pragma GCC optimize ("O3")
//#pragma GCC optimize ("Ofast")

#define F first
#define S second
#define MP make_pair
#define PB push_back
#define LBS 20
#define MOD 998244353 //((long long)1e9+7) //1e9+9
#define LEFT(i) (2*(i))
#define RIGHT(i) (2*(i)+1)
#define PAR(i) ((i)/2)

using namespace std;

typedef long long ll;
typedef double rat;
typedef long long bi;
typedef pair<int, int> ii;
typedef pair<int, ll> ill;
typedef std::vector<ii> vii;
typedef std::map<int, int> mii;
typedef bitset<LBS> bis;
typedef std::vector<bis> vbs;

void vin(std::vector<int> &a){
  for(auto &x: a)
    cin >> x;
}

void vout(std::vector<int> &a){
  for(auto x: a)
    cout << x << " ";
  cout << endl;
}

ll solve(std::vector<string> &vs, int l){
  if(!vs.size())
    return 0;
  map<char,int> mci; int cc=0;
  unordered_set<string> ss;
  for(auto s: vs){
    string rs=s;
    reverse(rs.begin(), rs.end());
    ss.insert(s);
    ss.insert(rs);
  }
  std::vector<std::vector<ll> > e(100, std::vector<ll> (100, 0));
  for(auto s: ss){
    if(!mci.count(s[0]))
      mci[s[0]]=cc++;
    if(!mci.count(s[l-1]))
      mci[s[l-1]]=cc++;
    // e.resize(cc);
    int a=mci[s[0]], b=mci[s[l-1]];
    e[a][b]++;
  }
  ll pos[cc][cc][cc];
  ll res=0;
  for(int i=0; i<cc; i++)
    for(int j=i; j<cc; j++)
      for(int k=j; k<cc; k++){
        pos[i][j][k]=0;
        for(int o=0; o<cc; o++){
          pos[i][j][k]+=(((e[i][o]*e[j][o])%MOD)*e[k][o])%MOD;
          pos[i][j][k]%=MOD;
        }
      }
  int mul[2][2][2]={
    {{24, 12}, {12, 4}},
    {{12, 6}, {4, 1}}
  };
  for(int i=0; i<cc; i++)
    for(int j=i; j<cc; j++)
      for(int k=j; k<cc; k++)
        for(int o=k; o<cc; o++){
          ll t=(((((pos[i][j][k]*pos[i][j][o])%MOD)*pos[i][k][o])%MOD)*pos[j][k][o])%MOD;
          res+=t*mul[i==j][j==k][k==o];
          res%=MOD;
        }

  return res;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  std::vector<std::vector<string> > vs(11);
  for(int i=0; i<n; i++){
    string s; cin >> s;
    vs[s.size()].PB(s);
  }
  ll res=0;
  for(int i=3; i<=10; i++){
    res+=solve(vs[i], i);
    res%=MOD;
  }
  cout << res << "\n";
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int sz = 62;
const ll mod = 998244353;

ll D[66][66][66], K[66][66];
vector <string> S[11];
ll n, ans;

int getv(char c)
{
	if('a' <= c && c <= 'z') return c - 'a';
	else if('A' <= c && c <= 'Z') return c - 'A' + 26;
	else return c - '0' + 52;
}

ll calc()
{
	int i, j, k, l;
	ll ret = 0, v;

	for(i=0; i<sz; i++) for(j=i; j<sz; j++){
		for(k=j; k<sz; k++) for(D[i][j][k] = l = 0; l<sz; l++){
			D[i][j][k] = (D[i][j][k] + K[i][l] * K[j][l] % mod * K[k][l]) % mod;
		}
	}

	for(i=0; i<sz; i++) for(j=i; j<sz; j++){
		for(k=j; k<sz; k++) for(l=k; l<sz; l++){
			v = 24;
			if(i == l) v /= 24;
			else if(i == k) v /= 6;
			else if(i == j) v /= 2;
			if(i != j){
				if(j == l) v /= 6;
				else if(j == k) v /= 2;
			}
			if(j != k){
				if(k == l) v /= 2;
			}

			v = v * (D[i][j][k] * D[i][j][l] % mod) % mod;
			v = v * (D[i][k][l] * D[j][k][l] % mod) % mod;

			ret = (ret + v) % mod;
		}
	}

	return ret;
}

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

	string s;
	int i, j, k;

	cin >> n;

	for(i=0; i<n; i++){
		cin >> s;
		S[s.size()].push_back(s);
		reverse(s.begin(), s.end());
		S[s.size()].push_back(s);
	}

	for(i=3; i<=10; i++){
		sort(S[i].begin(), S[i].end());
		S[i].erase(unique(S[i].begin(), S[i].end()), S[i].end());

		for(j=0; j<sz; j++){
			for(k=0; k<sz; k++){
				K[j][k] = 0;
			}
		}

		for(string &t: S[i]){
			K[getv(t[0])][getv(t[i - 1])] ++;
		}

		ans = (ans + calc()) % mod;
	}

	cout << ans << "\n";

	return 0;
}


#include<iostream>
#include<string>
#include<conio.h>
using namespace std;
int a,b,c;
string s;
main()
{
      cin>>s;
      if(s[0]>92) s[0]=s[0]-32;
      cout<<s;

      getch();
      }


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

int main() {
 string a,s;
 cin>>s;
a=toupper(s[0]);
cout<<a;
for (int i=1;i<s.size();i++){
    putchar(s[i]);
}
return 0;

}


#include <iostream>
#include <string>
using namespace std;
int main(){
	string c;
	cin>>c;
	if(c[0]>='A' && c[0]<='B'){
		cout<<c[0];
	}else{
		cout<<char(c[0]-32);
	}
	for(int i=1;i<c.size();i++){
		cout<<c[i];
	}
	return 0;
}


#include<stdio.h>
#include<math.h>

int numdiv(int x){
    int i, num = 0, d = sqrt(x);
    for (i = 1; i <= d; i++){
        if (x % i == 0)
            num++;
    }
    num *= 2;
    if (d*d == x)
        num-=1;
    return num;
}
int main(){
    int a, b, c, i, j, k, sum = 0;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &c);
    for (i = 1; i <= a; i++)
        for (j = 1; j <= b; j++)
            for (k = 1; k <= c; k++){
                //printf("%d", numdiv(i * j*k));
                sum += numdiv(i*j*k);}
    sum = sum % 1073741824;
    printf("%d", sum);
}


#include <fstream>
#include <math.h>
#include <set>
#include <string>
#include <vector>

using namespace std;

vector <int> d;

int kol_del(int a)
{
int k=int(sqrt(double(a)));
int kl=0;
for (long i=1;i<=k;i++) if (a%i==0) kl+=2;
if (k*k==a) kl--;
return kl;
}

int main()
{
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int a,b,c;
int _max;
scanf("%d %d %d",&a,&b,&c);
_max=a*b*c;
d.resize(_max+1);
int s=0;
for (int i=1;i<=_max;i++) d[i]=kol_del(i);
for (int i=1;i<=a;i++)
	for (int j=1;j<=b;j++)
		for (int e=1;e<=c;e++)
			{s+=d[i*j*e];s%=1073741824;}
printf("%d",s);
return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

#include<iostream>

#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<set>

#define mp make_pair
#define pb push_back
#define pf pop_front

#define forab(a, b) for(int i = a; i < b; i++)

using namespace std;

typedef pair<int, int> ii;
typedef unsigned long long uint64;
typedef long long int64;
typedef vector<int> vi;

int a, b, c;
int tt = 1073741824;
int primes[25] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97};
int pr[25];

int combine(int i, int j, int k){
  memset(pr, 0, 25 * sizeof(int));
  for(int t = 0; t < 25 && primes[t] <= i; t++) while(i % primes[t] == 0){pr[primes[t]]++; i /= primes[t];}
  for(int t = 0; t < 25 && primes[t] <= j; t++) while(j % primes[t] == 0){pr[primes[t]]++; j /= primes[t];}
  for(int t = 0; t < 25 && primes[t] <= k; t++) while(k % primes[t] == 0){pr[primes[t]]++; k /= primes[t];}

  int total = 1;
  for(int t = 0; t < 25; t++){
    total *= (pr[t]+1);
  }
  return total;
}

int main(int argc, char* argv[]){
  cin >> a >> b >> c;

  int64 num = 0;
  for(int i = 1; i <= a; i++){
    for(int j = 1; j <= b; j++){
      for(int k = 1; k <= c; k++){
        int64 temp = combine(i, j, k);
        num = (num + temp) % (int64)tt;
      }
    }
  }
  cout << num << endl;
  return 0;
}


#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

#include<iostream>

#include<algorithm>
#include<vector>
#include<deque>
#include<queue>
#include<set>

#define mp make_pair
#define pb push_back
#define pf pop_front

#define forab(a, b) for(int i = a; i < b; i++)

using namespace std;

typedef pair<int, int> ii;
typedef unsigned long long uint64;
typedef long long int64;
typedef vector<int> vi;

int a, b, c;
int tt = 1073741824;
int primes[25] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,     47,     53,     59,     61,     67,     71,     73,     79,     83,89,97};
int pr[25];

int combine(int i, int j, int k){
  memset(pr, 0, 25 * sizeof(int));
  for(int t = 0; t < 25 && primes[t] <= i; t++) while(i % primes[t] == 0){pr[primes[t]]++; i /= primes[t];}
  for(int t = 0; t < 25 && primes[t] <= j; t++) while(j % primes[t] == 0){pr[primes[t]]++; j /= primes[t];}
  for(int t = 0; t < 25 && primes[t] <= k; t++) while(k % primes[t] == 0){pr[primes[t]]++; k /= primes[t];}

  int total = 1;
  for(int t = 0; t < 25; t++){
    //printf("%d %d\n", t, pr[t]);
    total *= (pr[t]+1);
  }
  return total;
}

int main(int argc, char* argv[]){
  cin >> a >> b >> c;

  int64 num = 0;
  for(int i = 1; i <= a; i++){
    for(int j = 1; j <= b; j++){
      for(int k = 1; k <= c; k++){
        int64 temp = combine(i, j, k);
        num = (num + temp) % (int64)tt;
      }
    }
  }
  cout << num << endl;
  return 0;
}


#include<string>
#include <iostream>
#include <set>
#include<algorithm>
using namespace std;

int main()
{
    int n;
    string str;

    cin>>n;
    cin>>str;
   // cout<<str[1];
    int flag=0,max=0,len=0,start_u=0,start_b=0,num=0;
//cout<<max;
    for(int i=0;i<n;++i)
        {
            if((isalpha(str[i]&&i==0))||str[i]=='_'||str[i]==')')
                {
                if(isalpha(str[i]&&i==0))
                    i--;
                while(isalpha(str[++i]))
                    len++;
                if(len>max)
                    max=len;
                len=0;
                i--;
  //              cout<<max;
                continue;
                }

            if(str[i]=='(')
                {flag=1;
                start_u=1;
                    while(str[++i]!=')')
                        {
                            if(str[i]=='_')
                                start_u=1;
                            if(isalpha(str[i])&& start_u==1)
                                {
                                    num++;
                                    start_u=0;
                                }

                        }
                }
                i--;

        }
    cout<<max<<" "<<num;
    return 0;
}


#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<ctype.h>
using namespace std;

char str[260];
int o[260];
int is[260];

int main()
{
	int n;
	while (scanf("%d",&n))
	{
		scanf("%s", str);
		int len = strlen(str);

		memset(o, 0, sizeof(o));
		memset(is, 0, sizeof(is));
		int out = 0;
		int in = 0;
		int temp = 1;
		for (int i = 0; i < n; i++)
		{
			if (str[i] == '(')
				temp = 0;
			if (str[i] == ')')
				temp = 1;

			if (temp == 1)
			{
				if (isalpha(str[i]))
				{
					out++;
				}
				if (str[i] == '_' || str[i] == '(')
				{
					o[i] = out;
					out = 0;
				}
			}
		}
		int i = 0;
		int flag = 0;
		for (int i = 0; i < n; i++)
		{
			if (str[i] == '(')
			{
				for (int j = i + 1; j < n; j++)
				{
					if (isalpha(str[j]))
					{
						flag = 1;
					}
					if (flag==1&&str[j] == '_')
					{
						is[j] = 1;
						flag = 0;
					}
					if (str[j] == ')')
					{
						if (flag == 1)
						{
							is[j] = 1;
						}
						break;
					}
				}
			}
		}

		int max1 = 0;
		int max2 = 0;
		for (int i = 0; i < n; i++)
		{
			if (o[i] > max1)
				max1 = o[i];
			if (is[i]!=0)
				max2 ++;
		}

		cout << max1 <<" "<< max2<< endl;
	}
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gtx getchar
#define s(n)                    scanf("%lld",&n)
#define pf(n)                   printf("%lld",n)
#define sf(n)                   scanf("%lf",&n)
#define forall(i,a,b)           for(ll i = a ;i<b;i++)

void scan(){
    ll c1 = 0,c2 = 0;
    char ch = gtx();
    while(!isalpha(ch)) ch = gtx();
    int f1 = 0,f2 = 0;
    while(ch!=EOF){
        int m = 0;
        while(ch == '_') ch = gtx();
        if(ch == '(') {f1 =1 ; ch = gtx();}
        while(isalpha(ch) && f1 == 1) {c1++;ch = gtx();}
        while(isalpha(ch) && f1 == 0) {m++;ch = gtx();}
        if(ch == ')') {f1 = 0;ch = gtx();}
        c2 = c2>m?c2:m;
    }
    cout<<c1<<'\n'<<c2;
}

int main(){
    ll n;
    s(n);
    scan();
    return 0;
}


#define _USE_MATH_DEFINE
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>

using namespace std;

#define forn(i,n) for (int i=0;i<n;i++);

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n;
	cin>>n;
	string s;
	cin>>s;

	int i=0;
	int in=0;
	int li=0;
	vector <int> l;
	while (i<n) {
		if (s[i]=='(')
	{
		i++;
		li=0;
		while (s[i]!=')') {

			if (s[i]!='_')
				li++;
			else if(s[i]=='_' && li!=0) {
				li=0;
				in++;
			}

			i++;
			}
		if (li!=0) in++;
	}
		if (s[i]=='_') i++;
		if ( s[i]!='_' && s[i]!='(' && s[i]!=')') {
			li=0;
			while (i<n && s[i]!='_' && s[i]!='(') {
				li++;
				i++;
			}
			l.push_back(li);
		}

	}
	int t;
	if (l.size()!=0) {
	sort(l.begin(),l.end());
	 t=l[l.size()-1];}
	else  t=0;
	cout << t <<" "<< in;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define ll long long
const int MX=5000;
int n,m,a,b,mx;
string s;

int32_t main(){
    cin>>n;
    while(n){
        cin>>s;
        for(int i=0; i<s.size(); i++){
            if(int(s[i])<=96) mx++;
        }
        m=max(m,mx);
        n-=s.size();
    }
    cout<<m;
    return 0;
}


    #include <bits/stdc++.h>

    using namespace std;

    int main()
    {

        int n;
        cin>>n;
        string s;
        cin>>s;
        int answer =0;
        int pod=0;
        for (int i=0;i<n;i){

            if (isupper(s[i])){
                pod++;
            }
            if (s[i]==' '){
                pod=0;
            }

            answer= max(pod,answer);
        }
        cout<<answer;
    }


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long p;
	string str;
	scanf("%d",&p);
	long long sum=0,ans=0;
	for(int i=0;i<p;)
	{
        sum=0;
		cin>>str;
		i+=str.size()+1;
		for(int j=0;j<str.size();j++)
		if(str[j]>='A'&&str[j]<='Z')
			sum++;
		ans=max(sum,ans);
	}
	cout<<ans;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long p;
	string str;
	scanf("%d",&p);
	long long sum=0,ans=0;
	for(int i=0;i<p;)
	{
		cin>>str;
		i+=str.size()+1;
		for(int j=0;j<str.size();j++)

		if(str[j]>='A'&&str[j]<='Z')
			sum++;
		ans=max(sum,ans);
		sum=0;
	}
	cout<<ans;
}


#include <iostream>
#include <queue>
#include <vector>
using namespace std;

vector<vector<int>> adjlist;
int v[101];
int l;
vector<bool> used(10005);

queue<int> q;

bool func(int i, int j, int k)
{
    return ((v[j] + ((i + 1 <= k) ? (i + 1) : 2 * k - (i + 1)) <= l) ? true : false);
}

void construct(int n, int k)
{
    adjlist.clear();
    adjlist.resize(n * 2 * k + 1);
    for (int j = 0; j < n - 1; ++j)
    {
        for (int i = 0; i < 2 * k; ++i)
        {
            if (func(i, j, k) && func((i + 1) % (2 * k), j, k))
                adjlist[j * 2 * k + i].push_back(j * 2 * k + (i + 1) % (2 * k));
            if (func(i, j, k) && func((i + 1) % (2 * k), j + 1, k))
                adjlist[j * 2 * k + i].push_back((j + 1) * 2 * k + (i + 1) % (2 * k));
        }
    }
}

bool bfs(int a, int le, int ue)
{
    q.push(a);
    while (!q.empty())
    {
        int t = q.front();
        q.pop();
        if (t <= ue && t >= le)
            return true;
        used[t] = true;
        for (auto c : adjlist[t])
        {
            if (!used[c])
                q.push(c);
        }
    }
    return false;
}

void solve(int k, int n)
{
    for (int i = 0; i < 2 * k; ++i)
    {
        if (bfs(i, (n - 1) * 2 * k, (n - 1) * 2 * k + 2 * k - 1))
        {
            cout << "Yes" << endl;
            return;
        }
    }
    cout << "No" << endl;
}

int main()
{
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, k;
        cin >> n >> k;
        cin >> l;
        used.assign(n * 2 * k, false);
        for (int j = 0; j < n; ++j)
            cin >> v[j];
        construct(n, k);
        solve(k, n);
        while(!q.empty())
            q.pop();
    }
}


#include<bits/stdc++.h>

#define ll              long long int
#define ull             unsigned long long int
#define pii             pair < int, int>
#define pll             pair < ll, ll>
#define sc              scanf
#define scin(x)         sc("%d",&(x))
#define scln(x)         sc("%lld",&(x))
#define pf              printf
#define ms(a,b)         memset(a,b,sizeof(a))
#define pb(a)           push_back(a)
#define mp              make_pair
#define db              double
#define EPS             10E-10
#define ff              first
#define ss              second
#define endl            '\n'
#define sqr(x)          (x)*(x)
#define vi              vector< int >
#define vl              vector< ll >
#define vii             vector<vector< int > >
#define vll             vector<vector< ll > >
#define DBG1            pf("HI-1\n")
#define DBG2            pf("HI-2\n")
#define DBG3            pf("HI-3\n")
#define MOD             1000000007
#define CIN             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define RUN_CASE(t,T)   for(__typeof(t) t=1;t<=T;t++)
#define CASE(t)         printf("Case %d: ",t)
#define CASEL(t)        printf("Case %d:\n",t)
#define intlimit        2147483648
#define longlimit       9223372036854775808
#define infinity        (1<<28)
#define gcd(a, b)       __gcd(a,b)
#define lcm(a, b)       ((a)*(b)/gcd(a,b))
#define mx              1234567899
#define PI              2*acos(0.0)
#define all(v)          v.begin(),v.end()
#define rep(i,a,b)      for(__typeof(i) i=a; i<=b; i++)
#define rev(i,a,b)      for(__typeof(i) i=a; i>=b; i--)

using namespace std;

template<typename T>inline T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return sqr(POW(B,P/2));}
ll Bigmod(ll base, ll power, ll mod){if(power==0) return 1%mod; if(power==1) return base%mod; ll x = Bigmod(base,power/2,mod); x = (x*x)%mod; if(power%2){x = (x*(base%mod))%mod;}return x;}
ll Mulmod(ll base, ll power, ll mod){if(power==0) return 0; if(power==1) return base%mod; ll x = Mulmod(base,power/2,mod); x = (x+x)%mod; if(power%2){x = (x+(base%mod))%mod;}return x;}
ll BigMulmod(ll base, ll power, ll mod){if(power==0) return 1%mod; if(power==1) return base%mod; ll x = BigMulmod(base,power/2,mod); x = Mulmod(x,x,mod); if(power%2){x = Mulmod(x,(base%mod),mod);}return x;}
bool isVowel(char ch){ ch=toupper(ch); if(ch=='A'||ch=='U'||ch=='I'||ch=='O'||ch=='E') return true; return false;}
ll ModInverse(ll number, ll mod){return Bigmod(number, mod-2, mod);}
bool isConso(char ch){if (isalpha(ch) && !isVowel(ch)) return true; return false;}
int toInt(string s)  { int sm; stringstream ss(s); ss>>sm; return sm; }
bool isPrime( ll val ) { if( val == 2 ) return true ; if( val % 2 == 0 || val == 1 ) return false ; ll sqrt_N = (ll) ( ( double ) sqrt( val ) ) ; for( ll i = 3 ; i <= sqrt_N ; i += 2 ) { if( val % i == 0 ) return false ; } return true ; }
template<class T> string convert(T _input) { stringstream blah; blah << _input; return blah.str(); }
int distchar(char a, char b){int x = ((a - b)+26)%26;int y = ((b-a)+26)%26;return min(x,y);}

/**
// Ordered set
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T> using orderset = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//orderset<int> s ; //orderset<int>::iterator it ;
//orderset<int> X; //X.insert(1); //X.insert(2); //X.insert(4); //X.insert(8); //X.insert(16);
//cout<<*X.find_by_order(1)<<endl; // 2 //cout<<*X.find_by_order(2)<<endl; // 4 //cout<<*X.find_by_order(4)<<endl; // 16 //cout<<(end(X)==X.find_by_order(6))<<endl; // true
//cout<<X.order_of_key(-5)<<endl;  // 0 //cout<<X.order_of_key    (1)<<endl;   // 0 //cout<<X.order_of_key(3)<<endl;   // 2 //cout<<X.order_of_key(4)<<endl;   // 2 //cout<<X.order_of_key(400)<<endl; // 5
*/

///--------------Graph Moves--------------------------------------
///const int fx[] = {+1,-1,+0,+0};
///const int fy[] = {+0,+0,+1,-1};
///const int fx[] = {+0,+0,+1,-1,-1,+1,-1,+1}; ///King's move
///const int fy[] = {-1,+1,+0,+0,+1,+1,-1,-1}; ///king's Move
///const int fx[] = {-2,-2,-1,-1,+1,+1,+2,+2}; ///knight's move
///const int fy[] = {-1,+1,-2,+2,-2,+2,-1,+1}; ///knight's move
///---------------------------------------------------------------

bool cmp(int a,int b)
{
    return a>b;
}

ull Set(ull n, int pos) {return n = n|(1<<pos);}
ull Unset(ull n, int pos) {return n=n&~(1<<pos);}
bool check(ull n, int pos){return (bool)(n&(1<<pos));}

void Solve();
void TEST();

int main()
{
    TEST();
    return 0;
}

void TEST(){
    int t = 1, T;
    cin>>T;
    RUN_CASE(t,T){
        Solve();
    }
}

int n,k,l;
int d[55];

struct Data{
    int x,y,z;
    Data(){}
    Data(int a, int b, int c){
        x = a,y = b,z = c;
    }
    bool operator < (const Data &A) const{
        if(x!=A.x) return x < A.x;
        else if(y!=A.y) return y < A.y;
        else z < A.z;
    }
};

map<Data, int> M;

int func(int pos, int depth, int down){
    if(pos == n+1){
        return 1;
    }
    if(M[Data(pos,depth,down)]){
        return 0;
    }

    M[Data(pos,depth,down)] = true;

    depth += (down)?1:-1;
    if(depth == 0) down = 1;
    if(depth == k) down = 0;

    if(d[pos]+depth > l) return 0;

    return (func(pos, depth, down) || func(pos + 1, depth, down));
}

void Solve(){
    cin>>n>>k>>l;
    for(int i = 1; i <= n; i++){
        cin>>d[i];
    }
    cout<<(func(0,0,1)?"Yes":"No")<<endl;
    M.clear();
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000009LL
#define all(x) x.begin() , x.end()

void solve()
{
	ll n, k, l; cin >> n >> k >> l;
	ll arr[n][2 * k];
	vector<vector<ll> >v(n);
	for (int i = 0; i < n; i++) {
		cin >> arr[i][0];
		for (int j = 0; j <= k; j++) {
			arr[i][j] = arr[i][0] + j;
			if (arr[i][j] <= l) v[i].push_back(j);
		}
		for (int j = k + 1; j < 2 * k; j++) {
			arr[i][j] = arr[i][j - 1] - 1;
			if (arr[i][j] <= l) v[i].push_back(j);
		}
		/*for (auto x : v[i]) cout << x << " ";
		cout << "\n";*/
	}
	bool ok = 0;
	vector<ll>res(v[0].begin() , v[0].end());
	for (int i = 1; i < n; i++) {
		vector<ll>tp;
		for (auto y : res)
		{
			ll x = y;
			ll ct = 0;
			int index = find(v[i].begin() , v[i].end() , (x + 1) % (2 * k)) - v[i].begin();
			while (index < v[i].size() and (v[i][index] == ((x + 1) % (2 * k)) ) and ct < 2 )
			{
				tp.push_back((x + 1) % (2 * k));
				if (x == y) ct++;
				x = (x + 1) % (2 * k);
				index = (index + 1) % v[i].size();
			}
		}
		res.clear();
		res.assign(all(tp));
		/*for (auto x : res) cout << x << " ";
		cout << "\n";*/
	}
	if (res.size() > 0 and !res.empty()) cout << "YES";
	else cout << "NO";
	cout << "\n";
}
int32_t main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll t = 1; cin >> t;
	while (t--)
		solve();
	return 0;
}


#include<bits/stdc++.h>
#include <algorithm>
using namespace std;
using ll = long long;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

int n, k, l;
int d[101];
int p[201];
int dp[201][101];

bool dfs(int t, int i){
	if(i == n+1) return true;
	if(dp[t%(2*k)][i] != -1) return dp[t%(2*k)][i];
	if(d[i+1] + p[(t+1)%(2*k)] <= l)
		return dp[t%(2*k)][i] = dfs((t+1)%(2*k),i+1);
	else if(d[i] + p[(t+1)%(2*k)] <= l)
		return dp[t%(2*k)][i] = dfs((t+1)%(2*k),i);
	return dp[t%(2*k)][i] = false;
}

void solution(){
	cin >> n >> k >> l;
	d[0] = -k;
	for(int i=1;i<=n;i++) cin >> d[i];
	for(int i=0;i<=k;i++) p[i] = i;
	for(int i=k+1;i<2*k;i++) p[i] = p[i-1]-1;
	memset(dp,-1,sizeof(dp));
	bool ans = false;
	for(int i=0;i<2*k;i++){
		ans |= dfs(i,0);
		if(ans) break;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

int main(){

	fio; // fast input output
	int t = 1;
	cin >> t;
	while(t--){
		solution();
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,m,sum=0;
    cin>>n>>m;
    if(n%m==0)
    {
        for(int i=0;i<m;i++)
        {
            cout<<n/m<<" ";
        }
    }
    if(n%m!=0)
    {
        int x = n%m;
        int y = (n/m + 1)*m - n;;
        int z = min(x,y);
        for(int i=0;i<z;i++){
            cout<<n/m<<" ";
            sum+=n/m;
        }
        while(sum!=n)
        {
            cout<<n/m+1<<" ";
            sum+=(n/m+1);
        }

    }
}


#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<string>
#include<math.h>
#include<map>
#include<vector>
#include<queue>
using namespace std;
#define ll __int64
#define inf 1000000007
#define eps 0.000001
int max(int x,int y) {return x>y?x:y;}
int min(int x,int y) {return x<y?x:y;}
const int N=100005;
const int M=1000005;
int main()
{
	int i,j,k=1;
	int n,m,tt;
	int a,b;
	while(scanf("%d%d",&n,&m))
	{
		a=n/m;
		b=n%m;
		for(i=0;i<m;i++)
		{
			if(b) printf("%d ",a+1),b--;
			else printf("%d ",a);
		}
		printf("\n");
	}
	return 0;
}


#include<iostream>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
if(n%m==0)
for(int i=0;i<m;i++)
cout<<n/m<<endl;
else
{
int j=0;
while(j<m)
{
if(j<(n%m)) cout<<(n/m)+1<<endl;
else cout<<(n/m)<<endl;
}
}
return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define pb push_back
#define lli long long int
#define INF 1000000001

void solve() {
	int m, n;
	cin >> n >> m;
	int test = m;
	if (n % m == 0) {
		while (m--) {
			cout << n / test << " ";
		}
		cout << endl;
		return;
	}
	for (int i = 0; i < m - n % m; i++)
		printf("%d ", n / m);
	for (int i = 0; i < n % m; i++)
		printf("%d ", n / m + 1);

}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

#ifndef ONLINE_JUDGE

	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif
	int t; cin >> t;
	while (t--)
		solve();

	return 0;

}


#include <iostream>
#include <algorithm>
#include <cmath>
#include <assert.h>
#include <stdio.h>
#include <ctime>
#include <cstdlib>
#include <utility>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define INF (1<<30)
#define pii pair<int,int>
#define pll pair<unsigned long long,unsigned long long>
#define pdd pair<double,double>
#define eps 0

#ifdef ONLINE_JUDGE
#define debug(args...)
#else
#define debug(args...) fprintf(stderr,args)
#endif

using namespace std;

int n;

char dp[12][1<<10];
char dp2[12][1<<10][2];

int v[25];

int get(int,int);

int get2(int q1,int mask,int t){

	if(dp2[q1][mask][t]+1)
		return dp2[q1][mask][t];

	if(t == 1 && get(q1,mask))
		return dp2[q1][mask][t] = 1;

	int qnt = 0, maior = -1;

	for(int i=0;i<n;i++)
		if(mask & (1<<i))
			qnt++;

	if(qnt+q1 == 0)
		return dp2[q1][mask][t] = 0;

	for(int i=0;i<n;i++)
		if(mask & (1<<i))
			if(maior == -1 || v[i] > v[maior])
				maior = i;

	if(mask == 0 && q1 >= 2)
		return dp2[q1][mask][t] = 1;
	if(mask == 0)
		return dp2[q1][mask][t] = 1;

	for(int i=0;i<(1<<qnt);i++){

		if((mask|i) ^ mask)
			continue;

		if(i & (1<<maior) == 0)
			continue;

		for(int j=0;j<=q1;j++)
			if(get(j,i) && get2(q1-j,mask^i,1))
				return dp2[q1][mask][t] = 1;

	}

	return dp2[q1][mask][t] = 0;

}

int get(int q1,int mask){

	if(dp[q1][mask]+1)
		return dp[q1][mask];

	int qnt = 0, maior = -1;

	for(int i=0;i<n;i++)
		if(mask & (1<<i)){
			qnt++;
			if(maior == -1 || v[i] > v[maior])
				maior = i;
		}

	if(qnt+q1 != v[maior])
		return dp[q1][mask] = 0;

	if(qnt == 0)
		return dp[q1][mask] = 1;

	if(get2(q1,mask^(1<<maior),0))
		return dp[q1][mask] = 1;
	else
		return dp[q1][mask] = 0;

}

bool comp(int a,int b){
	return a > b;}

main(){

		scanf("%d",&n);

		int q1 = 0;

		for(int i=0;i<n;i++){
			scanf("%d",v+i);
			if(v[i] == 1)
				q1++;
		}

		if(n-q1 > 15){
			printf("NO\n");
			return 0;
		}

		sort(v,v+n,comp);

		memset(dp,-1,sizeof(dp));
		memset(dp2,-1,sizeof(dp2));

		n -= q1;
		if(get(q1,(1<<n)-1))
			printf("YES\n");
		else
			printf("NO\n");

}


#include<iostream>
#include<vector>
#include<fstream>
#include<queue>
#include<algorithm>
#include<list>
#include<cstdio>
#include<stack>
#include<cstring>
#include <climits>
#include<cmath>
#include<string>
#include <functional>
#include<sstream>
#include<map>
#include<set>

#pragma comment(linker, "/STACK:100000000000000")

using namespace std;
#define     For(i,a,b)        for (int i=a; i<b; i++)
#define     Rep(i,a)          for (int i=0; i<a; i++)
#define     ALL(v)            (v).begin(),(v).end()
#define     Set(a,x)          memset((a),(x),sizeof(a))
#define     EXIST(a,b)        find(ALL(a),(b))!=(a).end()
#define     Sort(x)           sort(ALL(x))
#define     UNIQUE(v)         Sort(v); (v).resize(unique(ALL(v)) - (v).begin())
#define     MP                make_pair
#define     SF                scanf
#define     PF                printf
#define     MAXN              1001
#define     MAXM              1001
#define     MOD               1000000007
#define     Dbug             cout<<"";
#define     EPS              1e-15
typedef long long ll;
typedef pair<int,int> pii;
int n, ind, dp[25][25][1<<16][2], tw[20];
vector<int> v;
int rec(int p, int rem, int mask, bool x)
{
	if(p==v.size()) return 0;
	if(~dp[p][rem][mask][x]) return dp[p][rem][mask][x];
	if(rem==1)
	{
		if(p+1<v.size()) return dp[p][rem][mask][x]=rec(p+1, v[p+1] , mask, 0);
		else return dp[p][rem][mask][x]=rec(p+1, 0 , mask, 0);
	}
	int ret=1+rec(p, rem-1, mask, 1);
	Rep(i, v.size()) if(!(mask&tw[i]))
	{
		if((v[i]<rem-1) || (x && v[i]<=rem-1))
		{
			ret=min(ret, rec(p, rem-v[i], mask|tw[i], 1));
		}
	}
	return dp[p][rem][mask][x]=ret;
}
int main(){
	//ios_base::sync_with_stdio(false);
	//freopen("a.in","r",stdin);
	Rep(i, 20) tw[i]=1<<i;
	cin>>n;
	int t;
	Rep(i, n)
	{
		cin>>t;
		v.push_back(t);
	}
	Sort(v);
	Rep(i, n) if(v[i]==2)
	{
		cout<<"NO";
		return 0;
	}
	int o=0;
	vector<int> nx;
	Rep(i, n) if(v[i]==1) o++;
	else nx.push_back(v[i]);
	if(n-o>=16 || o==n)
	{
		cout<<"NO";
		return 0;
	}
	v=nx;
	Set(dp, -1);
	int x=rec(0, v[0], 0, 0);
	if(x==o) cout<<"YES";
	else cout<<"NO";
	return 0;
}


#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

bool all_ok = false;
int n, a[24];
bool dp[24][1 << 24];

void dfs(int v, int mask) {
    if (dp[v][mask]) return;
    if (all_ok) return;
    if (v == n && mask + 1 == (1 << n)) {
        all_ok = true;
        return;
    }
    for (int i = 0; i < 1 << (n - v - 1); ++i) {
        if ((mask & i) == 0) {
            int x = i;
            int sum = 0;
            int p = 0;
            for (int j = n - 1; j >= 0; --j) {
                if (x % 2) {
                    sum += a[j];
                    if (sum > a[v]) break;
                    ++p;
                }
                x /= 2;
            }
            if ((p > 1 || p == 0) && sum + 1 == a[v]) dfs(v + 1, mask ^ i);
            if (all_ok) return;
        }
    }
    dp[v][mask] = true;
}

main () {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort (a, a + n);
    reverse (a, a + n);
    dfs(0, 1 << (n - 1));
    if (all_ok) cout << "YES";
    else cout << "NO";
}


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

vector <int> st[30];
int n,c[30];
bool g[30][1<<24],f[30][1<<24];

int count(int mask)
{
	int ret=0;
	while (mask)
	{
		ret+=mask%2;
		mask/=2;
	}
	return ret;
}

int total(int mask)
{
	int ret=0,i=0;
	while (mask)
	{
		if (mask%2) ret+=c[++i];
		mask/=2;
	}
	return ret;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&c[i]);
	sort(&c[1],&c[n+1]);
	for (int i=1;i<=n;i++)
	{
		for (int mask=0;mask<1<<i;mask++)
		{
			if (count(mask)>=2 && total(mask)+1==c[i])
				g[i][mask]=true,st[i].push_back(mask);
			else g[i][mask]=false;
		}
	}
	f[0][0]=true;
	for (int i=1;i<=n;i++)
	{
		if (c[i]==1) f[i][(1<<i)-1]=true;
		for (int mask=0;mask<1<<(i-1);mask++)
		{
			for (int j=0;j<st[i].size();j++)
			{
				if ((st[i][j]|mask)==mask) continue;
				f[i][mask|(1<<(i-1))]|=f[i-1][mask^st[i][j]];
			}
		}
	}
	if (f[n][1<<(n-1)]) printf("YES\n");
	else printf("NO\n");

	return 0;
}


#include <iostream>
#include <string>
using namespace std;
int main()
{
	long long int number;
	string num;
	cin >> number;
	for (int i = 1; i <= number; i++)
	{
		num += to_string(i);
		if (num.length() >= number)
		{
			cout << num[number - 1];
			return 0;
		}
	}
}


#include "string"
#include <iostream>

using namespace std;

int main()
{
	string s;
	int i = 1;

	while (s.length() <= 1000000000000)
	{
		s += to_string(i);
		i++;
	}
	int k;
	std::cin >> k;
	std::cout << s[k - 1];
	return 0;
}


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

int main()
   { ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // ll t;
    //cin>>t;
   //while(t--)
  ll n;
  cin>>n;
  vector<ll>v,v1;

  for(ll i=1;;i++)
  {   if(i<=9)
      v1.push_back(i);
     else
    {  ll g=i;
      while(g!=0)
     {   ll a=g%10;
     v.push_back(a);
        g=g/10;
     }
     for(ll j=v.size()-1;j>=0;j--)
     {
         v1.push_back(v[j]);
     }
     v.clear();
    }

      if(v1.size()==n)
      {
          break;
      }

  }
 /* for(ll i=0;i<n;i++)
  {
     cout<<v1[i]<<" ";
  }*/
  cout<<v1[n-1];
   return 0;

   }


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(){
    int k;
    scanf("%d",&k);
    char s[10000];
    char in[12];
    s[0]='\0';
    for(int i=1;i<=k;i++){
        sprintf(in,"%d",i);
        strcat(s,in);
    }
    printf("%c",s[k-1]);
}


#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{

  unsigned __int64 b,mx=0,tm=0,v;
    unsigned __int64 y,m;
    cin>>m>>b;
    v=m*b;
    for(double i=1;i<=v;i++)
    {
        y=-i/m+b;
        tm=0;
        if(y==(int)y)
        {
            //cout<<y<<"\n";
            for( double j=0; j<=y;j++)
               {
                   for( double k=0; k<=i;k++)
                   {
                       tm=tm+k+j;
                   }
               }
               if(mx<tm)
               {
                   mx=tm;
               }

    }

    }

   cout<<mx<<"\n";

getch();
    return 0;
}


#include <iostream>
#include <conio.h>
using namespace std;
unsigned __int64 arifm(unsigned __int64 a)
{
   unsigned __int64 x;
   x=(a+1)*a/2;
    return(x);
}
int main()
{

  unsigned __int64 b=0,mx=0,tm=0,v=0,m=0;
  double y=0,i=0;
    cin>>m>>b;
    v=m*b;
    for(i=0;i<=v;i++)
    {
        y=-i/m+b;
        tm=0;
        if(y==(int)y)
        {
            tm=arifm(y)*(i+1)+arifm(i)*(y+1);
           // cout<<y<<"\n";
        }

          //cout<<tm<<"\n";
               if(mx<tm)
               {
                   mx=tm;
               }

    }

   cout<<mx<<"\n";
   //cout<<arifm(18)<<"\n";

getch();
    return 0;
}


#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int arr(int a)
{
    int x=0;
    for(int i=1;i<=a;i++)
    {
        if(a-1!=0)
        {
           x=x+i;
        }
        else
        {
            x=0;
            break;
        }
    }
    return(x);
}
int ars(int a)
{
    int x=0;
    for(int i=1;i<=a;i++)
    {
           x=x+i;
    }
    return(x);
}
int main()
{

    int b,mx=0,tm,v;
    double y,m;
    cin>>m>>b;
    v=m*b;
    for(double i=1;i<v;i++)
    {
        y=-i/m+b;
        //cout<<i<<"\n";
        //cout<<y<<"\n";
        tm=2*ars(y)+(y+1)*i+2*arr(i-1)+y*(i-1);
        //cout<<tm<<"\n";
        if(y==(int)y)
        {
            if(mx<tm)
            {
                mx=tm;
            }
        }

    }

  // cout<<2*ars(3)+4*2+2*ars(2-1)+3*(2-1);
  cout<<mx;
    getch();
    return 0;
}


#include <iostream>
#include <conio.h>
#include <math.h>
using namespace std;
int main()
{

    int b,mx=0,tm=0,v;
    double y,m;
    cin>>m>>b;
    v=m*b;
    for(double i=1;i<v;i++)
    {
        y=-i/m+b;
        tm=0;
        //cout<<i<<"\n";
        if(y==(int)y)
        {

            for(int j=0; j<=y;j++)
               {
                   for(int k=0; k<=i;k++)
                   {
                       tm=tm+k+j;
                   }
               }
               //cout<<i<<"  "<<y<< "  "<<tm<<"\n";
            if(mx<tm)
            {
                mx=tm;
            }
        }

    }

  // cout<<2*ars(3)+4*2+2*ars(2-1)+3*(2-1);
  cout<<mx;
    getch();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define FOR(i,x,y) for(int i=x;i<y;i++)
#define in(n) scanf("%d",&n)
#define out(n) printf("%d\n",n)
#define SORT(v)  sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend()) //Sort vector in descending order using reverse iterators
#define MAX(v) *max_element(v.begin(), v.end())
#define MIN(v) *min_element(v.begin(), v.end())
#define FAST ios_base::sync_with_stdio(false)

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
typedef vector< iii > viii;
typedef long long ll;
//

int main(){
      FAST;
      int n,k,x;
      int a[n];
      cin>>n>>k>>x;
      FOR(i,0,n)
      cin>>a[i];
      int c=0;
      FOR(i,0,n-2)
      c+=a[i];
      c+=k*x;
      cout<<c;
      return 0;
}


#include<cstdio>
#include<cstring>
#define N 11000
using namespace std;
int max(int a,int b){if(a>b)return a;return b;}
int min(int a,int b){if(a<b)return a;return b;}
int n,t[N+1];
int f[N+1];
int st[N+1],tot;
struct edge
{
	int to,last;
}e[((N*N)>>1)+1];
void add(int a,int b)
{
	e[++tot].to=b;
	e[tot].last=st[a];
	st[a]=tot;
}
int dfs(int u)
{
	if(f[u]!=-1)
		return f[u];
	f[u]=t[u];
	for(int i=st[u];i!=0;i=e[i].last)
		f[u]=max(f[u],dfs(e[i].to)+t[u]);
	return f[u];
}
int main()
{
	scanf("%d",&n);
	for(int i=1,k,v;i<=n;i++)
	{
		scanf("%d %d",&t[i],&k);
		while(k--)
		{
			scanf("%d",&v);
			add(i,v);
		}
	}
	memset(f,-1,sizeof(f));
	int ans=-2147483647;
	for(int i=1;i<=n;i++)
		if(f[i]==-1)
			ans=max(ans,dfs(i));
	printf("%d",ans);
	return 0;
}


#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	freopen("input.txt", "rt", stdin);
//	freopen("output.txt", "wt", stdout);
	int n, k, x;
	cin >> n >> k >> x;

	vector<int> deals(n);

	for (int i = 0; i < n; i++) {
		cin >> deals[i];
	}
	for (int i = n - 1; i >= n - k ; i--) {
		deals[i] = x;
	}

	int total = 0;
	for (int i = 0; i < n; i++) {
		total +=deals[i];
	}

	cout << total << endl;

	return 0;
}


#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
	int *arr;
	int size;

	int k, x, sum = 0;
	cin >> size >> k >> x;

	if (size <= 0) {
		cerr << "Invalid size" << endl;
		return 1;
	}

	arr = new int[size];

	for (int i = 0; i < size; i++) {

		cin >> arr[i];
	}

	int temp; // временная переменная для обмена элементов местами

			  // Сортировка массива пузырьком
	for (int i = 0; i < size - 1; i++) {
		for (int j = 0; j < size - i - 1; j++) {
			if (arr[j] > arr[j + 1]) {
				// меняем элементы местами
				temp = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = temp;
			}
		}
	}

	for (int i = size - k; i < size; i++) {
		arr[i] = x;
	}
		for (int i = 0; i < size; i++) {
		sum = sum + arr[i];
	}
	cout << sum;

	delete[] arr; // освобождение памят

	_getch();
	return 0;
}


/******************************************
 	AUTHOR : PRATIK
 INSTITUTION : BITS PILANI HYDERABAD CAMPUS
******************************************/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<int> vi;
typedef multiset<int> ms;
typedef set<int> s;
typedef vector<double> vid;
typedef multiset<double> msd;
typedef set<double> sd;
#define sp setprecision
#define N 100005
#define MOD 1000000007
#define dd double
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define F first
#define S second
int main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ios_base& scientific (ios_base& str);

	ll a,b,i=0,p,cu=0;
	cin>>a>>b;
	ll y=a;
	ll A[a],B[a];

		while(i<b-1) {cin>>A[i++]; y--;}
		cin>>A[i++];
		i=b-2;
		y--;
		while(i>=0 && y>=0) {cin>>B[i];
				if(B[i]*A[i]==0 ) A[i]=0;
				else if(A[i]==B[i] ) cu++;
				i--;
				y--;
			}

         while(y--){
			cin>>p;
			if(p==1) cu++;
		}

	REP(i,0,b) if(A[i]==1) cu++;
	cout<<cu<<endl;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
#include <unordered_map>
using namespace std;
int arr[1000000],j,n,max1=1,counter,a,dis[10000000],dis1[10000000];

int main()
{
	cin>>n>>a;
	for(int i=1;i<=n;i++)
		{
			cin>>arr[i];
			if(arr[i])
			{
				if(dis[abs(i-a)]==0)
				{
				 dis[abs(i-a)]=1;
				 dis1[j++]=abs(i-a);
				}
			}
	   }
	for(int i=0;i<j;i++)
	{
		for(int d=1;d<=n;d+=dis1[i])
		{
			if(arr[d]==1)
				counter++;
		}
		max1=max(max1,counter);
		counter=0;
	}
	cout<<max1;

}


#include<cstdio>
#include<algorithm>
#include<iostream>

using namespace std;

typedef long long LL;

int inf = 1000000009;

int findB(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid = (low + high)/2;

        val = x - y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}

int findA(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid =  low + (high-low)/2;

        val = x + y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}
int main(){

    int a, b, x1, y1, x2, y2;
    int a1, a2, b1, b2, ret;

    cin>> a >> b >> x1>> y1 >> x2 >> y2;

    a1 = findA(x1, y1, a);
    //cout<< a1<<endl;
    a2 = findA(x2, y2, a);

    b1 = findB(x1, y1, b);
    b2 = findB(x2, y2, b);

    ret = max( abs(a1-a2), abs(b1-b2));

    cout<< ret;

    return 0;
}


#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#define INF 1000000000
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

LL a,b,x1,y,x2,y2;

int main(){
	cin >> a >> b >> x1 >> y >> x2 >> y2;
	LL da;
	LL k1=x1+y;
	LL k2=x2+y2;
	LL mi=min(k1,k2);
	LL ma=max(k1,k2);
	while (mi%(2*a)!=0) mi++;
	while (ma%(2*a)!=0) ma--;
	if (mi>ma) da=0;
	else da=(ma-mi)/(2*a)+1;
	LL db;
	LL t1=x1-y;
	LL t2=x2-y2;
	mi=min(t1,t2);
	ma=max(t1,t2);
	while (mi%(2*b)!=0) mi++;
	while (ma%(2*b)!=0) ma--;
	if (mi>ma) db=0;
	else db=(ma-mi)/(2*b)+1;
	cout << max(da,db);

}


#include<cstdio>
#include<algorithm>
#include<iostream>

using namespace std;

typedef long long LL;

int inf = 100000009;

int findB(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid = (low + high)/2;

        val = x - y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}

int findA(int x, int y, int a){

    LL low = -inf;
    LL high = inf;
    LL val, mid;

    while(low < high){
        mid = (low + high)/2;

        val = x + y - 2*a*mid;
        if( val < 0){
            high = mid;
        }
        else low = mid+1;
    }

    return low;
}
int main(){

    int a, b, x1, y1, x2, y2;
    int a1, a2, b1, b2, ret;

    cin>> a >> b >> x1>> y1 >> x2 >> y2;

    a1 = findA(x1, y1, a);
    a2 = findA(x2, y2, a);

    b1 = findB(x1, y1, b);
    b2 = findB(x2, y2, b);

    ret = max( abs(a1-a2), abs(b1-b2));

    cout<< ret;

    return 0;
}


#include<iostream>
#include<stdlib.h>
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<utility>

using namespace std;

long  a,b,x,x2,y,y2,res1,res2,res,xx,xx2,yy,yy2,k,k2,i;

int main()
{
	cin>>a>>b>>x>>y>>x2>>y2;

	yy=y;
	yy2=y2;
	for(i=1;i<=2*b;i++)
	{
		yy+=1;
		if((yy-x)%(2*b)==0) k=(yy-x)/(2*b);

		yy2+=1;
		if((yy2-x2)%(2*b)==0) k2=(yy2-x2)/(2*b);
	}
	res1=abs(k2-k);

	xx=x;
	xx2=x2;
	for(i=1;i<=2*a;i++)
	{
		xx+=1;
		if((y+xx)%(2*a)==0) k=(xx+y)/(2*a);

		xx2+=1;
		if((y2+xx2)%(2*a)==0) k2=(xx2+y2)/(2*a);
	}

	res2=abs(k2-k);

	res=max(res1,res2);

	cout<<res;

	return 0;
}


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

int main (){
int n,m,k,con1,con2;
cin>>n>>m>>k;
for(int i=1;i<=k;i++){
    con1=n*i;
    con2+=con1;
}
con2-con2-m;
if(con2>0)
    cout<<con2;
else
    cout<<"0";
}


#include <iostream>
#include <conio.h>
using namespace std;
int main()
{int w;
  long int n,k,s,m;
    cin>>k;
    cin>>n;
    cin>>w;
    s=k*w*(w+1)/2;
    m=s-n;
    cout<<m;
    getch();
    return 0;
}


#include<iostream>
#include<conio.h>

using namespace std;

void main()
{
	int k,w;
	long int n;
	cin>>k>>n>>w;
	for (int i=1;i>=n;i++)
		w *= i;
	cout<<n-w;
	_getch();
}


#include<bits/stdc++.h>
using namespace std;
long long n,k,w,i,j,c,d,s;
int main()
{
    cin>>n>>k>>w;
    d=(2*n)-n;
    //cout<<d;
    s=(w/2)*((2*n)+(w-1)*d);
    if(n==0||(s-k)<=0)
        cout<<"0";
    else
        cout<<abs(s-k);
}


#include <stdio.h>
int main()
{
    int a,b,c,x,y,z,sum,v[7],i;
    while(scanf("%d%d%d",&x,&y,&z))
    {
        scanf("%d%d%d",&a,&b,&c);
        for(i=1;i<=6;i++)
            scanf("%d",v+i);
        sum=0;
        if(z>c) sum+=v[4];
        else if(z<0) sum+=v[3];
        if(y>b) sum+=v[2];
        else if(y<0) sum+=v[1];
        if(x>a) sum+=v[6];
        else if(a<0) sum+=v[5];
        printf("%d\n",sum);
    }
    return 0;
}


#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <iterator>
#include <utility>

using namespace std;

template< class T > T _abs(T n) { return (n < 0 ? -n : n); }
template< class T > T sq(T x) { return x * x; }
template< class T > T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a%b) : a); }
template< class T > T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); }
template< class T > T _max(T a, T b) { return (!(a < b) ? a : b); }
template< class T > T _min(T a, T b) { return (a < b ? a : b); }
template< class T > inline T MOD(T n, T m){    return (n%m+m)%m;}

//string monthName[]={"","January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
//string dayName[]={"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

//int xx[]={1,0,-1,0};              int yy[]={0,1,0,-1}; //4 Direction
//int xx[]={1,1,0,-1,-1,-1,0,1};    int yy[]={0,1,1,1,0,-1,-1,-1};//8 direction
//int xx[]={2,1,-1,-2,-2,-1,1,2};   int yy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

#define REP(i,n)for (i=0;i<n;i++)
#define FOR(i,p,k) for (i=p; i<k;i++)
#define FORE(i, p, k) for(i=p; i<=k; i++)
#define FOREACH(it,x) for(__typeof((x).begin()) it=(x.begin()); it!=(x).end(); ++it)
#define FORD(i,n)    for(i=n;i>=0;i--)

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define REV(s, e) reverse(s, e)

#define ll long long int
#define CLR(p) memset(p, 0, sizeof(p))
#define mset(p, v) memset(p, v, sizeof(p))
#define ALL(c) c.begin(), c.end()
#define SZ(c) (int)c.size()
#define pb(x) push_back(x)
#define vs vector<string>
#define vi vector<int>
#define vii vector< pair<int, int> >

#define fs first
#define sc second
#define MP(x, y) make_pair(x, y)
#define pii pair< int, int >
#define psi pair< string, int >
#define pq priority_queue

#define LOG(x,BASE) (log10(x)/log10(BASE))
#define EQ(a,b)     (fabs(a-b)<ERR)

/**biwise operation**/
#define two(X)          (1<<(X))
#define twoL(X)         (((ll)(1))<<(X))
#define setBit(mask,i)  (mask|two(i))
#define contain(S,X)    (((S)&two(X))!=0)
#define containL(S,X)   (((S)&twoL(X))!=0)
#define popc(i) (__builtin_popcount(i))

#define csprint printf("Case %d: ", ++t);
#define PI acos(-1)
#define ERR 10E-5

const int INF = 0x7f7f7f7f;

#define MAX 100005

/** debugging**/
#define bug(x) cout<<"->"<<#x<<": "<<x<<endl;
#define debug(args...)          {cout<<" #--> ";dbg,args; cerr<<endl;}
struct debugger
{    // Taken from rudradevbasak
    template<typename T> debugger& operator , (const T& v)    {        cerr<<v<<" ";        return *this;    }
} dbg;
template<class T> void deb(T e){cout<<e<<endl;}
template<class T1,class T2> void deb(T1 e1,T2 e2){cout<<e1<<"\t"<<e2<<endl;}
template<class T1,class T2,class T3> void deb(T1 e1,T2 e2,T3 e3){cout<<e1<<"\t"<<e2<<"\t"<<e3<<endl;}
template<class T1,class T2,class T3,class T4> void deb(T1 e1,T2 e2,T3 e3,T4 e4){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<endl;}
template<class T1,class T2,class T3,class T4,class T5> void deb(T1 e1,T2 e2,T3 e3,T4 e4,T5 e5){cout<<e1<<"\t"<<e2<<"\t"<<e3<<"\t"<<e4<<"\t"<<e5<<endl;}
template<class T> void deb(vector<T> e){int i;REP(i,SZ(e)) cout<<e[i]<<" ";cout<<endl;}
template<class T> void deb(vector<T> e,int n){int i;REP(i,n) cout<<e[i]<<" ";cout<<endl;}
template<class T> void deb(vector< basic_string<T> > e){int i,j;REP(i,SZ(e)) {REP(j,SZ(e[i])) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void deb(vector< basic_string<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j];cout<<endl;} cout<<endl;}
template<class T> void deb(vector< vector<T> > e,int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<"\t";cout<<endl;} cout<<endl;}
template<class T> void deb(T e[MAX][MAX],int row,int col){int i,j;REP(i,row) {REP(j,col) cout<<e[i][j]<<" ";cout<<endl;}}
template<class T> void deb(T e[],int row){int i;REP(i,row) cout<<e[i]<<" ";cout<<endl;}

double deg2rad(double x){ return (PI*x)/180.0; }
double rad2deg(double x){ return (180.0*x)/PI; }

//prime check
template<class T> inline bool isPrime(T n){if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
//int,double is converted to string
template<class T> string toString(T n){ostringstream oss;oss<<n;oss.flush();return oss.str();}
//string is converted to int
int toInt(string s){int r=0;istringstream sin(s);sin>>r;return r;}
//string is converted to Long long
bool IsVowel(char ch){ch=tolower(ch);if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u')return true;return false;}
//isUpperCase
bool isUpper(char c){return c>='A' && c<='Z';}
//isLowerCase
bool isLower(char c){return c>='a' && c<='z';}
//compute b^p
ll Pow(ll B,ll P){  ll R=1; while(P>0)  {if(P%2==1) R=(R*B);P/=2;B=(B*B);}return R;}
//compute b^p%m
int BigMod(ll B,ll P,ll M){ ll R=1; while(P>0)  {if(P%2==1){R=(R*B)%M;}P/=2;B=(B*B)%M;} return (int)R;}
//print a number in binary format with n length
void binprint(ll mask,ll n){ll i;string s="";do{s+=(mask%2+'0');mask/=2;}while(mask);reverse(ALL(s) );s=string(max(n-SZ(s),0LL),'0')+s;for(i=SZ(s)-n;i<SZ(s);i++) printf("%c",s[i]);printf("\n");}
//ASCII Chart
void ASCII_Chart(){int i,j,k;printf("ASCII Chart:(30-129)\n");FOR(i,30,50){REP(j,5){k=i+j*20;printf("%3d---> '%c'   ",k,k);}printf("\n");}}

int x_, y_, z_, x, y, z;
int a[7];

int main()
{
    //READ("in.txt");
    //WRITE("out.txt");
    int i, j, k, result, t=0, tcase;
    while(scanf("%d %d %d", &x, &y, &z ))
    {
        scanf("%d %d %d", &x_, &y_, &z_);
        for(i=1; i<=6; i++)
        {
            scanf("%d", &a[i]);
        }

        int sum=0;

        if(y<0) sum+= a[1];
        if(y>y_) sum+= a[2];
        if(z<0) sum+= a[3];
        if(z>z_) sum+= a[4];
        if(x<0) sum+= a[5];
        if(x>x_) sum+= a[6];

        printf("%d\n", sum);
    }
}


#include <iostream>
using namespace std;
int a[10];
int main()
{
#ifndef ONLINE_JUDGE
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
#endif
    int sum = 0;
    int x, y, z;
    int x1, y1, z1;
    scanf("%d%d%d", &x, &y, &z);
    scanf("%d%d%d", &x1, &y1, &z1);
    for (int i = 1; i <= 6; i++)
        scanf("%d", &a[i]);

    if (y > y1)
        sum += a[2];
    if (y < 0)
        sum += a[1];

    if (z > z1)
        sum += a[4];
    if (z < 0)
        sum += a[3];

    if (y > y1)
        sum += a[6];
    if (y < 0)
        sum += a[5];
    printf("%d", sum);
    return 0;
}


//          be name khoda

#include <algorithm>
#include <iostream>
#include <vector>
#include <set>

using namespace std;

typedef long long ll;
const int maxN = 8000;

struct node{
    bool lr;
    int x, ind, pl;
};

int l[maxN][maxN], r[maxN][maxN], type[maxN], lr[maxN][2], n;
vector <node> timeLine[maxN];
set <int> ans;

int lg(ll v)
{
    int k = 0;
    while((1 << k) < v)
        k++;
    return k;
}

void count(int n)
{
    ll a[maxN], sum[maxN];
    a[1] = sum[1] = 1;
    for(int i = 2; i < n; i++)
    {
        a[i] = a[i - 1] + lg(a[i - 1]);
        sum[i] = sum[i - 1] + a[i];
    }
    for(int i = 6500; i < 7000; i++)cerr << i << " : " << a[i] << ", " << sum[i] << endl;
}

bool cmp(node l, node r)
{
    return l.pl < r.pl;
}

int main()
{
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < m; i++)
    {
        int t;
        cin >> t;
        type[i] = t;
        if(t == 1)
        {
            int t, lll, rr, x;
            cin >> t >> lll >> rr >> x;
            node a, b;
            a.ind = b.ind = i;
            a.lr = 0;
            b.lr = 1;
            a.pl = lll;
            b.pl = rr;
            a.x = b.x = x;
            timeLine[t].push_back(a);
            timeLine[t].push_back(b);
        }
        else
        {
            int t, v;
            cin >> t >> v;
            lr[i][0] = t;
            lr[i][1] = v;
            int lll = v, rr = v;
            for(int j = t; j <= n; j++)
            {
                l[i][j] = lll;
                r[i][j] = rr;
                int lgl = lg(lll);
                if(1 << (lgl) == lll)
                    lll = lll + lgl;
                else
                    lll = lll + lgl;
                rr = rr + lg(rr);
                //cerr << i << " , " << j << " : " << l[i][j] << " " << r[i][j] << endl;
            }
        }
    }
    for(int i = 1; i <= n; i++)
        sort(timeLine[i].begin(), timeLine[i].end(), cmp);
    for(int i = 0; i < m; i++)
        if(type[i] == 2)
        {
            ans.clear();
            for(int j = lr[i][0]; j <= n; j++)
            {
                //cerr << i << ", " << j << endl;
                for(int k = 0; k < timeLine[j].size(); k++)
                    if(k >= l[i][j] && k <= r[i][j] && timeLine[j][k].ind < i)
                        ans.insert(timeLine[j][k].x);
            //  for(int k = l[i][j]; k <= r[i][j]; k++)
            //  {
            //
            //  }
            }
            cout << ans.size() << endl;
        }
    cin >> n;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <memory.h>
#define pii pair<int,int>
using namespace std;
typedef long long ll;

const int N = 7123;
const int L = 1e7;

multiset<pii> s[N];

int par[L*2];

int main(){
   // freopen("input.txt","r",stdin);// freopen("output.txt","w",stdout);

    int n, m;

    n = 1;
    for(int i=1;n<L;++i){
        if(i&(i-1)) par[n++] = i; else{
            par[n++] = i;
            par[n++] = i;
        }
    }

    scanf("%d%d",&n,&m);

    for(int k=0;k<m;++k){
        int tp;
        scanf("%d",&tp);
        if(tp==1){
            int t,l,r,x;
            scanf("%d%d%d%d",&t,&l,&r,&x);
            while(t){
                s[t].insert(make_pair(l, x));
                s[t].insert(make_pair(r+1, -x));
                l = par[l];
                r = par[r];
                --t;
            }
        }else{
            int t,v;
            scanf("%d%d",&t,&v);
            map<int,int> q;
            for(multiset<pii>::iterator it = s[t].begin(); it!=s[t].end(); it++){
                if(it->first>v) break;
                int x = it->second;
                if(x > 0) q[x]++;
                else{
                    x=-x;
                    q[x]--;
                    if(!q[x]) q.erase(x);
                }
            }

            printf("%d\n",q.size());
        }
    }

    return 0;
}