// C++17. Input: alphabet size, text length, then cipher values. Output score histograms and all maximizing adjusted keys.
#include <algorithm>
#include <array>
#include <iostream>
#include <vector>
using namespace std;
using Key = array<int,4>;
struct Block {int n=0; bool f=false; int h[4][29]{};};
int main(){
 ios::sync_with_stdio(false);cin.tie(nullptr);
 int A,n;
 while(cin>>A>>n){
   if(A<2 || A>29 || n<0)return 2;
   vector<Block> B(1);
   for(int i=0;i<n;i++){
     int c; if(!(cin>>c) || c<0 || c>=A)return 3;
     if(c==0){B.back().f=true;B.emplace_back();}
     else{auto &b=B.back(); b.h[(b.n++)&3][c]++;}
   }
   vector<array<int,2>> hist(n+1);
   array<vector<Key>,2> winners;
   int top[2]={-1,-1},floor=-2*n-1;
   for(int a=0;a<A;a++)for(int b=0;b<A;b++)for(int c=0;c<A;c++)for(int d=0;d<A;d++){
     Key k={a,b,c,d};int bonus[4]={!a,!b,!c,!d};
     int u[4]={0,floor,floor,floor},v[4]={0,floor,floor,floor};
     for(const Block &s:B){
       int w[4]={s.h[0][a]+s.h[1][b]+s.h[2][c]+s.h[3][d],s.h[0][b]+s.h[1][c]+s.h[2][d]+s.h[3][a],
                 s.h[0][c]+s.h[1][d]+s.h[2][a]+s.h[3][b],s.h[0][d]+s.h[1][a]+s.h[2][b]+s.h[3][c]};
       int ua[4],va[4];
       for(int i=0;i<4;i++){int e=(i+s.n)&3;ua[e]=u[i]+w[i];va[e]=v[i]+w[i];}
       if(s.f){
         for(int i=0;i<4;i++){int p=(i+3)&3;u[i]=max(ua[i],ua[p]+bonus[p]);v[i]=max(va[i]+1,va[p]+bonus[p]);}
       }else for(int i=0;i<4;i++){u[i]=ua[i];v[i]=va[i];}
     }
     int z[2]={*max_element(u,u+4),*max_element(v,v+4)};
     for(int m=0;m<2;m++){hist[z[m]][m]++;if(z[m]>top[m]){top[m]=z[m];winners[m].clear();}if(z[m]==top[m])winners[m].push_back(k);}
   }
   cout<<"BEGIN "<<A<<' '<<n<<'\n';
   for(int i=0;i<=n;i++)if(hist[i][0]||hist[i][1])cout<<"H "<<i<<' '<<hist[i][0]<<' '<<hist[i][1]<<'\n';
   for(int m=0;m<2;m++)for(auto k:winners[m])cout<<"W "<<m<<' '<<k[0]<<' '<<k[1]<<' '<<k[2]<<' '<<k[3]<<'\n';
   cout<<"END\n";
 }
}
