#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define deg(x) cout << #x << '=' << x << endl
#define mes(a, b) memset(a, b, sizeof(a))
#define mk(a, b) make_pair(a, b)
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, x;
	cin >> t;
	while (t--)
	{
		s.clear();
		cin >> x >> s;
		int pos = 0;
		LL len = s.length();
		while (len < x)
		{
			string tmp = s.substr(pos + 1, len);
			int num = s[pos] - '0' - 1;
			while (num)
			{
				if (len <= x)
					s += tmp;
				len += tmp.length();
				num--;
			}
			pos++;
		}
		while (pos < x)
		{
			LL stmp = (len - pos - 1 + mod) % mod;
			LL tnum = s[pos] - '0' - 1;
			len = (len + tnum * stmp) % mod;
			pos++;
		}
		len %= mod;
		cout << len << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define deg(x) cout << #x << '=' << x << endl
#define mes(a, b) memset(a, b, sizeof(a))
#define mk(a, b) make_pair(a, b)
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, x;
	cin >> t;
	while (t--)
	{
		s.clear();
		cin >> x >> s;
		int pos = 0;
		LL len = s.length();
		while (len < x)
		{
			string tmp = s.substr(pos + 1, len);
			int num = s[pos] - '0' - 1;
			while (num)
			{
				if (len <= x)
					s += tmp;
				len += tmp.length();
				num--;
			}
			pos++;
		}
		while (pos < x)
		{
			LL stmp = len - pos - 1;
			LL tnum = s[pos] - '0' - 1;
			len = (len + tnum * stmp) % mod;
			pos++;
		}
		len %= mod;
		cout << len << endl;
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
#define deg(x) cout << #x << '=' << x << endl
#define mes(a, b) memset(a, b, sizeof(a))
#define mk(a, b) make_pair(a, b)
const int inf = 0x3f3f3f3f;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
string s;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t, x;
	cin >> t;
	while (t--)
	{
		s.clear();
		cin >> x >> s;
		int pos = 0;
		LL len = s.length();
		if (len == 1)
		{
			cout << 1 << endl;
			continue;
		}
		while (len < x && pos < x)
		{
			string tmp = s.substr(pos + 1, len);
			int num = s[pos] - '0' - 1;
			while (num)
			{
				if (len <= x)
					s += tmp;
				len += tmp.length();
				num--;
			}
			pos++;
		}
		while (len >= x && pos < x)
		{
			LL stmp = (len - pos - 1 + mod) % mod;
			int num = s[pos] - '0' - 1;
			len = (len + num * stmp % mod) % mod;
			pos++;
		}
		len %= mod;
		cout << len << endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
long long t,x;
string sx;
long long s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>x;
		cin>>sx;
		long long n=sx.size();
		for(int i=n;i>=1;i--)
		{
			s[i]=sx[i-1]-'0';
		}
		long long tot=n;
		for(long long num=1;num<=x;num++)
		{
			long long k=tot+1;
			if(k<=x)
			{
				for(long long i=1;i<=s[num]-1;i++)
				{
					if(k>x)
					{
						break;
					}
					for(long long j=num+1;j<=tot;j++)
					{
						if(k>x)
						{
							break;
						}
						s[k++]=s[j];
					}
				}
			}
			tot+=(tot-num)*(s[num]-1);
			tot%=1000000007;
		}
		cout<<tot<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,n;
char s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>s;
		ll l=strlen(s);
		ll ans=l;
		for(ll i=1;i<=n;i++)
		{
			ll sx=s[i-1]-'0';
			ans=i+sx*(ans-i+10000007);
			ans%=1000000007;
			if(l<n)
			{
				ll x=l-i;
				for(ll j=1;j<sx;j++)
				{
					for(ll k=i;k<l;k++)
					{
						if(k+j*x<n)
						{
							s[k+j*x]=s[k];
						}
					}
				}
				l=min(l+(sx-1)*x,n);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int t,x;
string sx;
int s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>x;
		cin>>sx;
		int n=sx.size();
		for(int i=n;i>=1;i--)
		{
			s[i]=sx[i-1]-'0';
		}
		long long tot=n;
		for(int num=1;num<=x;num++)
		{
			int k=tot+1;
			if(k<=x)
			{
				for(int i=1;i<=s[num]-1;i++)
				{
					if(k>x)
					{
						break;
					}
					for(int j=num+1;j<=tot;j++)
					{
						if(k>x)
						{
							break;
						}
						s[k++]=s[j];
					}
				}
			}
			tot+=(tot-num)*(s[num]-1);
			tot%=1000000007;
		}
		cout<<tot<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long t,x;
string sx;
long long s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>x;
		cin>>sx;
		long long n=sx.size();
		for(long long i=n;i>=1;i--)
		{
			s[i]=sx[i-1]-'0';
		}
		long long tot=n;
		for(long long num=1;num<=x;num++)
		{
			long long k=tot-num;
			if(tot<x)
			{
				for(long long i=1;i<s[num];i++)
				{
					for(long long j=num+1;j<=tot;j++)
					{
						if(j+i*k<=x)
						{
							s[j+i*k]=s[j];
						}
					}
				}
			}
			tot=num+s[num]*k;
			tot%=1000000007;
		}
		cout<<tot<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,n;
char s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>s;
		ll l=strlen(s);
		ll ans=l;
		for(ll i=1;i<=n;i++)
		{
			ll sx=s[i-1]-'0';
			ans=i+sx*(ans-i+1000000007);
			ans%=1000000007;
			if(l<n)
			{
				ll x=l-i;
				for(ll j=1;j<sx;j++)
				{
					for(ll k=i;k<l;k++)
					{
						if(k+j*x<n)
						{
							s[k+j*x]=s[k];
						}
					}
				}
				l=min(l+(sx-1)*x,n);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll t,n;
char s[1000005];
int main()
{
	cin>>t;
	while(t--)
	{
		cin>>n>>s;
		ll l=strlen(s);
		ll ans=l;
		for(ll i=1;i<=n;i++)
		{
			ll sx=s[i-1]-'0';
			ans=i+sx*(ans-i);
			ans%=1000000007;
			if(l<n)
			{
				ll x=l-i;
				for(ll j=1;j<sx;j++)
				{
					for(ll k=i;k<l;k++)
					{
						if(k+j*x<n)
						{
							s[k+j*x]=s[k];
						}
					}
				}
				l=min(l+(sx-1)*x,n);
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	//io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		ll f=0;
		while(i<=x)
		{
			//cout<<s<<" "<<i<<"\n";
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(ans-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
			    if(ans<=x+1&&f==0)
				{
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
			else f=1;
				ans=((ans%m)+(1%m)*(ans%m-i%m-1%m+m)%m)%m;

				i++;

			}
			else
			{
			    if(ans<=x+1&&f==0)
				{

				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
			else
			f=1;
				//cout<<"sadsas";
				ans=(ans%m+(2%m)*(ans%m-i%m-1%m+m)%m)%m;
				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		ll f=0;
		while(i<=x)
		{
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(ans-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
			    if(ans<=x+1&&f==0)
				{
					f=1;
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
				ans=((ans%m)+(1%m)*(ans-i-1)%m)%m;

				i++;

			}
			else
			{
			    if(ans<=x+1&&f==0)
				{
					f=1;
				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
				//cout<<"sadsas";
				ans=(ans%m+(2%m)*(ans-i-1)%m)%m;

				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		while(i<=x)
		{
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(s.length()-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
				ans=(ans%m+1%m*(ans-i-1)%m)%m;
				if(ans<=x+1)
				{
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
				i++;

			}
			else
			{
				//cout<<"sadsas";
				ans=(ans%m+2%m*(ans-i-1)%m)%m;
				if(ans<=x+1)
				{
				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		while(i<=x)
		{
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(ans-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
			    if(ans<=x+1)
				{
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
				ans=((ans%m)+(1%m)*(ans-i-1)%m)%m;

				i++;

			}
			else
			{
			    if(ans<=x+1)
				{
				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
				//cout<<"sadsas";
				ans=(ans%m+(2%m)*(ans-i-1)%m)%m;

				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		ll f=0;
		while(i<=x)
		{
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(ans-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
			    if(ans<=x+1&&f==0)
				{
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
			else f=1;
				ans=((ans%m)+(1%m)*(ans-i-1)%m)%m;

				i++;

			}
			else
			{
			    if(ans<=x+1&&f==0)
				{

				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
			else
			f=1;
				//cout<<"sadsas";
				ans=(ans%m+(2%m)*(ans-i-1)%m)%m;

				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<bits/stdc++.h>
using namespace std;
#define ll  long long int
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
//find_by_order() ->  iterator to the k-th largest element (counting from zero)
//order_of_key() ->    the number of items in a set that are strictly smaller than our item aka index in set.
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define m 1000000007
int main()
{
	io;

	ll t;
	cin>>t;
	while(t--)
	{
		ll x;
		cin>>x;
		x--;
		string s;
		cin>>s;
		ll n=s.length();
		ll ans=n;
		ll i=0;
		ll len=n;
		ll f=0;
		while(i<=x)
		{
			//cout<<i<<" ";
			if(s[i]=='1')
			{
				ans+=0*(ans-i-1);
				i++;
			}
			else if(s[i]=='2')
			{
			    if(ans<=x+1&&f==0)
				{
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
			}
			else f=1;
				ans=((ans%m)+(1%m)*(ans-i-1)%m)%m;

				i++;

			}
			else
			{
			    if(ans<=x+1)
				{
					f=1;
				//	cout<<"sad";
				string tmp=s.substr(i+1,s.length()-i-1);
				s.append(tmp);
				s.append(tmp);
			}
			else
			f=1;
				//cout<<"sadsas";
				ans=(ans%m+(2%m)*(ans-i-1)%m)%m;

				i++;
			}

//cout<<s<<" ";
		}
		cout<<ans<<"\n";
	}
	}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; string s;
		cin >> x >> s;
		long long l = 0, size  = s.length(),step = 0, max = 1e9+7;
		int p = x;
		while(p-->0)
		{
			++l;
			int t = s[l-1]-'0';
			step = ((t-1)*((size - l) % max)) % max;
			size = (size + step) % max;

			while(--t>0 && s.length() < x)
				s = s + s.substr(l, string::npos);
		}
		cout << size << "\n";
	}

}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; string s;
		cin >> x >> s;
		unsigned long long l = 0, size  = s.length(),step = 0, max = 1e9+7;
		int p = x;
		while(p-->0)
		{
			++l;
			int t = s[l-1]-'0';
			step = ((t-1)*((size - l) % max)) % max;
			size = (size + step) % max;
			string ss = s;
			while(--t>0 && s.length() < x)
				ss = ss + s.substr(l, string::npos);
			s = ss;
		}
		cout << size << "\n";
	}

}


#include<iostream>
#include<string>

using namespace std;

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; string s;
		cin >> x >> s;
		unsigned long long l = 0, size  = s.length(),step = 0, max = 1e9+7;
		int p = x;
		while(p-->0)
		{
			++l;
			int t = s[l-1]-'0';
			step = ((t-1)*((size - l) % max)) % max;
			size = (size + step) % max;
			string ss = s.substr(l, string::npos);;
			while(--t>0 && s.length() < x)
				s = s + ss;
		}
		cout << size << "\n";
	}

}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; char s[1000];
		cin >> x >> s;
		unsigned long long l = 0, size  = strlen(s),step = 0, max = 1e9+7;
		int p = x;
		vector<char> st(s, s+size);
		while(p-->0)
		{
			++l;
			int t = st[l-1]-'0';
			step = ((t-1)*((size - l) % max)) % max;
			size = (size + step) % max;

			if(st.size() < x)
				{
					vector<char> sub(st.begin() + l, st.end());
					while(--t>0)
						st.insert(st.end(), sub.begin(), sub.end());
				}
		}
		cout << size << "\n";
	}

}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; char s[1000];
		cin >> x >> s;
		long long l = 0, size  = strlen(s), max = 1e9+7;
		int p = x;
		vector<char> st(s, s+size);
		while(p-->0)
		{
			++l;
			int t = st[l-1]-'0';
			size = (size + (t-1)*(size - l)) % max;

			if(st.size() < x)
				{
					vector<char> sub(st.begin() + l, st.end());
					while(--t>0)
						st.insert(st.end(), sub.begin(), sub.end());
				}
		}
		cout << (size % max + max) % max << "\n";
	}

}


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

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		unsigned x; char s[1000];
		cin >> x >> s;
		unsigned long long l = 0, size  = strlen(s),step = 0, max = 1e9+7;
		int p = x;
		vector<char> st(s, s+size);
		while(p-->0)
		{
			++l;
			int t = st[l-1]-'0';
			step = ((t-1)*((size - l) % max)) % max;
			size = (size + step) % max;
			vector<char> sub(st.begin() + l, st.end());
			while(--t>0 && st.size() < x)
				st.insert(st.end(), sub.begin(), sub.end());
		}
		cout << size << "\n";
	}

}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll; //typedef __int128 lll;
typedef pair<int,int> pii;
typedef double lf;
#define repeat(i,a,b) for(int i=(a),iE=(b);i<iE;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,iE=(a);i>=iE;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define qwq {cout<<"qwq"<<endl;}
const int N=3001010;
const int inf=1e9;
const int mod=1000000007;
//#define int ll
char s[N],c[N];
int T,n;
signed main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>T;
	while(T--){
		cin>>n>>s; int len=strlen(s),lenn=len;
		int p=0;
		bool f=true;
		while(f){
			p++;
			int l=p-1,r=lenn-1;
			repeat(i,l+1,lenn+1)
				c[i-l-1]=s[i]; //cout<<c<<endl;
			int tlen=r-l;
			//c=s.substr(l+1,r-l);
			repeat(i,0,s[l]-'1'){
				strcat(s+lenn,c); lenn+=tlen;
				if(lenn>=n){f=false;break;}
			}
		}
		//cout<<s<<endl;
		repeat(p,1,n+1){
			//cout<<(len+mod)%mod<<endl;
			len=(len+(ll)(len-p)*(s[p-1]-'1')%mod+mod)%mod;
		}
		cout<<(len+mod)%mod<<endl;
	}
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;
const int S = 5e2+7;
const int MOD = 1e9+7;

int T, x;
int a[N];
char s[S];

int main()
{
    scanf("%d", &T);
    while (T--) {
        scanf("%d%s", &x, s+1);
        int n = strlen(s+1);
        for (int i = 1; i <= n; ++i)
            a[i] = s[i]-'0';
        for (int i = 1, flag = 0, sz; i <= x; ++i) {
            if (!flag) {
            sz = (n+(n-i)*(a[i]-1)%MOD)%MOD;
            for (int j = n+1, k = i+1; j <= min(x, sz); ++j, ++k) {
                if (k > n) k = i+1;
                a[j] = a[k];
            }
            }
            if (sz >= x) flag = 1;
            (n += (n-i)*(a[i]-1)%MOD) %= MOD;
        }
        printf("%d\n", n);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;
const int S = 5e2+7;
const int MOD = 1e9+7;

int T, x;
int a[N];
string s;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> T;
    while (T--) {
        cin >> x >> s;
        long long n = s.length();
        for (int i = 0; i < x; ++i) {
            n = (n-1)*(s[i]-'0')%MOD;
            if (!n) break;
            if ((int)s.length() < x) {
                string tmp = s.substr(i+1);
                for (int i = 1; i < s[i]-'0'; ++i)
                    s += tmp;
            }
        }
        cout << (n+x)%MOD << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1e6+7;
const int MOD = 1e9+7;

int T, x;
string s;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> T;
    while (T--) {
        cin >> x >> s;
        long long n = s.length();
        for (int i = 0; i < x; ++i) {
            n = (n-1)*(s[i]-'0')%MOD;
            if (n == 0) break;
            if ((int)s.length() < x) {
                string tmp = s.substr(i+1);
                for (int j = 1; j < s[i]-'0'; ++j)
                    s += tmp;
            }
        }
        cout << (n+x)%MOD << endl;
    }
    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b){
    return (a * b) % MOD;
}

ll pow(ll a, ll e){
    if (e == 0) return 1;
    if (e%2 == 1) return mul(a, pow(a, e - 1));
    return pow(mul(a, a), e/2);
}

ll add (ll x, ll y){
    return (x + y) % MOD;
}

void solve() {
    ll x;
    cin >> x;
    string s;
    cin >> s;
    vector<char> sp;
    for (int i = 0; i < s.size(); i++){
        sp.push_back(s[i]);
    }
    ll cursor = 0;
    while (sp.size() <= x+5){
        cursor++;
        ll n = sp.size();
        for (int j = 0; j < s[cursor-1] - '0' - 1; j++){
            for (int k = cursor; k < n; k++){
                sp.push_back(sp[k]);
            }
        }
    }
    ll rgh = sp.size() - cursor - 1;
    while (cursor < x){
        cursor++;
        rgh = mul(rgh, sp[cursor-1] - '0') - 1;
    }
    cout << (cursor + rgh + 1) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    while (t--){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b){
    return (a * b) % MOD;
}

ll pow(ll a, ll e){
    if (e == 0) return 1;
    if (e%2 == 1) return mul(a, pow(a, e - 1));
    return pow(mul(a, a), e/2);
}

ll add (ll x, ll y){
    return (x + y) % MOD;
}

void solve() {
    ll x;
    cin >> x;
    string s;
    cin >> s;
    vector<char> sp;
    for (int i = 0; i < s.size(); i++){
        sp.push_back(s[i]);
    }
    ll cursor = 0;
    while (sp.size() <= x+5){
        if (cursor >= x){
            break;
        }
        cursor++;
        ll n = sp.size();
        for (int j = 0; j < sp[cursor-1] - '0' - 1; j++){
            for (int k = cursor; k < n; k++){
                sp.push_back(sp[k]);
            }
        }
    }
    ll rgh = sp.size() - cursor - 1;
    while (cursor++ < x){
        rgh = mul(rgh, sp[cursor-1] - '0') - 1;
    }
    cout << add(cursor, rgh) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    while (t--){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b){
    return (a * b) % MOD;
}

ll pow(ll a, ll e){
    if (e == 0) return 1;
    if (e%2 == 1) return mul(a, pow(a, e - 1));
    return pow(mul(a, a), e/2);
}

ll add (ll x, ll y){
    return (x + y) % MOD;
}

void solve() {
    ll x;
    cin >> x;
    string s;
    cin >> s;
    if (x == 1 || s.size() == 1){
        cout << 1 << endl;
        return;
    }
    vector<char> sp;
    for (int i = 0; i < s.size(); i++){
        sp.push_back(s[i]);
    }
    ll cursor = 0;
    while (sp.size() <= x+5){
        cursor++;
        ll n = sp.size();
        for (int j = 0; j < sp[cursor-1] - '0' - 1; j++){
            for (int k = cursor; k < n; k++){
                sp.push_back(sp[k]);
            }
        }
    }
CONTINUE:
    ll rgh = sp.size() - cursor - 1;
    while (cursor < x){
        cursor++;
        rgh = mul(rgh, sp[cursor-1] - '0') - 1;
    }
    cout << (cursor + rgh + 1) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    while (t--){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b){
    return (a * b) % MOD;
}

ll pow(ll a, ll e){
    if (e == 0) return 1;
    if (e%2 == 1) return mul(a, pow(a, e - 1));
    return pow(mul(a, a), e/2);
}

ll add (ll x, ll y){
    return (x + y) % MOD;
}

void solve() {
    ll x;
    cin >> x;
    string s;
    cin >> s;
    vector<char> sp;
    for (int i = 0; i < s.size(); i++){
        sp.push_back(s[i]);
    }
    ll cursor = 0;
    while (sp.size() <= x+5){
        if (cursor >= x){
            break;
        }
        cursor++;
        ll n = sp.size();
        for (int j = 0; j < sp[cursor-1] - '0' - 1; j++){
            for (int k = cursor; k < n; k++){
                sp.push_back(sp[k]);
            }
        }
    }
CONTINUE:
    ll rgh = sp.size() - cursor - 1;
    while (cursor < x){
        cursor++;
        rgh = mul(rgh, sp[cursor-1] - '0') - 1;
    }
    cout << (cursor + rgh + 1) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    while (t--){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

const ll MOD = 1e9 + 7;

ll mul(ll a, ll b){
    return (a * b) % MOD;
}

ll pow(ll a, ll e){
    if (e == 0) return 1;
    if (e%2 == 1) return mul(a, pow(a, e - 1));
    return pow(mul(a, a), e/2);
}

ll add (ll x, ll y){
    return (x + y) % MOD;
}

void solve() {
    ll x;
    cin >> x;
    string s;
    cin >> s;
    vector<char> sp;
    for (int i = 0; i < s.size(); i++){
        sp.push_back(s[i]);
    }
    ll cursor = 0;
    while (sp.size() <= x+5){
        if (cursor >= x){
            break;
        }
        cursor++;
        ll n = sp.size();
        for (int j = 0; j < sp[cursor-1] - '0' - 1; j++){
            for (int k = cursor; k < n; k++){
                sp.push_back(sp[k]);
            }
        }
    }
    ll rgh = sp.size() - cursor - 1;
    while (cursor++ < x){
        rgh = mul(rgh, sp[cursor-1] - '0') - 1;
    }
    cout << add(cursor + 1, rgh) << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int t;
    cin >> t;
    while (t--){
        solve();
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const ll md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

ll add(ll a, ll b){
	return (a + b) % md;
}

ll sub(ll a, ll b){
	ll ans = (a - b) % md;
	while (ans < 0) ans += md;
	return ans;
}

ll mul(ll a, ll b){
	return (a * b) % md;
}

void solve(){
	cin >> n >> s;
	ll len = s.size();
	int i = 0;
	while (true){
		if (s.size() >= n) break;
		int sl = s[i] - '0' - 1, dodai = s.size() - i;
		while (s.size() < n && sl){
			s += s.substr(i + 1, dodai);
			--sl;
		}
		++i;
	}
	//cout << s << ' ';
	for (int i = 0; i < n; ++i)
		len = add(len, mul(sub(len, i + 1), (s[i] - '0' - 1)));
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const int md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

void solve(){
	cin >> n >> s;
	int len = s.size();
	int i = 0;
	while (true){
		if (s.size() >= n) break;
		int sl = s[i] - '0' - 1, dodai = s.size() - i;
		while (s.size() < n && sl){
			s += s.substr(i + 1, dodai);
			--sl;
		}
		++i;
	}
	for (int i = 0; i < n; ++i)
		len = (len + (int)((ll)(len - (i + 1) + md) % md * (s[i] - '0' - 1)) % md) % md;
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const int md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

void solve(){
	cin >> n >> s;
	int len = s.size();
	for (int i = 0; i < n; ++i){
		int sl = s[i] - '0';
		if (s.size() < n)
			for (int j = 1; j < sl; ++j)
				if (s.size() < n){
					for (int k = i + 1; k < len; ++k)
						if (s.size() < n) s += s[k];
						else break;
				}
				else break;
		int tg = (len - (i + 1) + md) % md;
		len = ((ll)tg * sl + (i + 1)) % md;
	}
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const int md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

void solve(){
	cin >> n >> s;
	ll len = s.size();
	int i = 0;
	while (true){
		if (s.size() >= n) break;
		int sl = s[i] - '0' - 1, dodai = s.size() - i;
		while (s.size() < n && sl){
			s += s.substr(i + 1, dodai);
			--sl;
		}
		++i;
	}
	for (int i = 0; i < n; ++i)
		len = (len + ((len - (i + 1) + md) % md * (s[i] - '0' - 1)) % md + md) % md;
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const ll md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

void solve(){
	cin >> n >> s;
	ll len = s.size();
	int i = 0;
	while (true){
		if (s.size() >= n) break;
		int sl = s[i] - '0' - 1, dodai = s.size() - i;
		while (s.size() < n && sl){
			s += s.substr(i + 1, dodai);
			--sl;
		}
		++i;
	}
	//cout << s << ' ';
	for (int i = 0; i < n; ++i)
		len = (len + ((len - (i + 1) + md) % md * (s[i] - '0' - 1)) % md + md * md) % md;
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define st first
#define nd second

typedef pair<int, int> ii;

struct re{
	int x, y;
};

const int md = 1e9 + 7;
const int N = 1e3 + 10;

int n, T;
string s;

void solve(){
	cin >> n >> s;
	ll len = s.size();
	int i = 0;
	while (true){
		if (s.size() >= n) break;
		int sl = s[i] - '0' - 1, dodai = s.size() - i;
		while (s.size() < n && sl){
			s += s.substr(i + 1, dodai);
			--sl;
		}
		++i;
	}
	for (int i = 0; i < n; ++i)
		len = (len + ((len - (i + 1) + md) % md * (s[i] - '0' - 1)) % md) % md;
	cout << len;
}

int main(){
	//srand (time(NULL));
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//freopen("tam.inp", "r", stdin);
	//freopen("tam.out", "w", stdout);
	cin >> T;
	while (T--){
		solve();
		cout << "\n";
	}
	return 0;
}


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

#define ll long long

int main()
{
	ll t;	cin >> t;
	while (t--)
	{
		ll x;	cin >> x;
		string a;	cin >> a;	ll n = a.size();
		string b = a;
		ll ix = 0;

		vector <char> _b(b.begin(), b.end());
		while ( (_b.size() <= x) && (ix < _b.size() - 1) ){
			if (_b.size() < x){
	            vector<char> sub(_b.begin() + ix + 1, _b.end());
				ll rep = (_b[ix] - '1');
				while (rep --)
					_b.insert(_b.end(), sub.begin(), sub.end());
			}
			ix += 1;

		}

		ll i = 0, fr = n, mod = 1000000007, res = n;
		while(i < x){
			ll rep = _b[i] - '1';
			res = (res + (res - i - 1)*rep) % mod;
			i ++;
		}
		cout << res << "\n";
	}
}

// 111

// 321
// 321212112121


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

#define ll long long

int main()
{
	ll t;	cin >> t;
	while (t--)
	{
		ll x;	cin >> x;
		string a;	cin >> a;	ll n = a.size();
		ll ix = 0, mod = 1000000007, res = n;
		string b = a;
		while (ix < x){
			ll rep = b[ix] - '1';
			// cout << b << " " << rep << " " << ix <<  "\n";

			if (b.size() < x){
				string nx = b.substr(ix + 1, n - ix - 1);
				ll per = rep;
				while (per --)	b += nx;
			}

			// cout << res << " " << (res - ix - 1) << " "  << ix << " " << rep << "\n";
			// cout << (res + (res - ix - 1)*rep) << "\n\n";

			res = res + (res - ix - 1)*rep;
			ix += 1;
		}
		cout << res << "\n";
	}
}


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

#define ll long long

int main()
{
	ll t;	cin >> t;
	while (t--)
	{
		ll x;	cin >> x;
		string a;	cin >> a;	ll n = a.size();

		string b = a;
		ll ix = 0;
		while ( (b.size() < x) && (ix < b.size() - 1) ){
			string nx = b.substr(ix + 1, b.size() - ix - 1);
			ll rep = (b[ix] - '0') - 1;
			while ( (rep --) && (b.size() < x) ) 	b += nx;
			ix += 1;
		}

		// cout << b << "\n";
		ll i = 0, fr = n, pr = 0, mod = 1000000007, res = n;
		while(i < x){
			pr = i + 1;
			fr = n - i - 1;
			n += fr * (b[i] - '0' - 1);
			// res = (n%mod + ((fr%mod) * (b[i] - '0' - 1) )%mod ) % mod;
			i ++;
		}
		cout << n%mod << "\n";
	}
}

// 111

// 321
// 321212112121


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

#define ll long long

int main()
{
	ll t;	cin >> t;
	while (t--)
	{
		ll x;	cin >> x;
		string a;	cin >> a;	ll n = a.size();

		ll ix = 0, mod = 1000000007, res = n;
		vector <char> b(a.begin(), a.end());
		while (ix < x){
			ll rep = b[ix] - '1';
			if (b.size() < x){
				vector <char> nx(b.begin() + ix + 1, b.end());
				ll per = rep;
				while (per --)
					b.insert(b.end(), nx.begin(), nx.end());
			}
			res = (res%mod + ((res - ix - 1)%mod * (rep%mod))%mod   )%mod;
			ix += 1;
		}
		// cout << res << "\n";
		cout << (res % mod + mod)%mod << "\n";
	}
}


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

#define ll long long

int main()
{
	ll t;	cin >> t;
	while (t--)
	{
		ll x;	cin >> x;
		string a;	cin >> a;	ll n = a.size();
		string b = a;
		ll ix = 0;

		vector <char> _b(b.begin(), b.end());
		while (ix < n){
			if (_b.size() < x){
	            vector<char> sub(_b.begin() + ix + 1, _b.end());
				ll rep = (_b[ix] - '1');
				while (rep --)
					_b.insert(_b.end(), sub.begin(), sub.end());
			}
			ix += 1;
		}

		ll i = 0, fr = n, mod = 1000000007, res = n;
		while(i < x){
			ll rep = _b[i] - '1';
			res = (res + (res - i - 1)*rep) % mod;
			i ++;
		}
		cout << res << "\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MT make_tuple
#define PB push_back
typedef long long ll;

int N, P;
string s;
char c;

int main () {
	cin >> N >> P >> s;
	string t = s;
	if (P == 1) return puts("NO"), 0;
	if (P == 2) {
		if (N == 1) {
			if (s[0] == 'a') puts("b");
			else puts("NO");
		} else {
			if (s[0] == 'a') puts("ba");
			else puts("NO");
		}
		return 0;
	}
	for (int a = N; a--; ) {
		c = s[a] + 1;
		while ((a-2 >= 0 && c == s[a-2]) ||
				(a-1 >= 0 && c == s[a-1])) c++;
		if (c >= 'a' + P) continue;
		fo(i, a+1, N) {
			s[i] = 'a';
			while ((i-2 >= 0 && s[i] == s[i-2]) ||
					(i-1 >= 0 && s[i] == s[i-1])) s[i]++;
			assert(s[i] < 'a' + P);
		}
		s[a] = c;
		assert(s[a] < 'a' + P);
		cout << s << endl;
		assert(s > t);
		return 0;
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MT make_tuple
#define PB push_back
typedef long long ll;

int N, P;
string s;
char c;

int main () {
	cin >> N >> P >> s;
	string t = s;
	if (P == 1) return puts("NO"), 0;
	if (P == 2) {
		if (N == 1) {
			if (s[0] == 'a') puts("b");
			else puts("NO");
		} else {
			if (s[0] == 'a') puts("ba");
			else puts("NO");
		}
		return 0;
	}
	for (int a = N; a--; ) {
		c = s[a] + 1;
		while ((a-2 >= 0 && c == s[a-2]) ||
				(a-1 >= 0 && c == s[a-1])) c++;
		if (c >= 'a' + P) continue;
		fo(i, a+1, N) {
			s[i] = 'a';
			while ((i-2 >= 0 && s[i] == s[i-2]) ||
					(i-1 >= 0 && s[i] == s[i-1])) s[i]++;
			assert(s[i] < 'a' + P);
		}
		s[a] = c;
		assert(s[a] < 'a' + P);
		cout << s << endl;
		assert(s > t);
		fo(i, 0, N-1) assert(s[i] != s[i+1]);
		fo(i, 0, N-2) assert(s[i] != s[i+2]);
		return 0;
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MT make_tuple
#define PB push_back
typedef long long ll;

int N, P;
string s;
char c;

int main () {
	cin >> N >> P >> s;
	if (P == 1) return puts("NO"), 0;
	if (P == 2) {
		if (N == 1) {
			if (s[0] == 'a') puts("b");
			else puts("NO");
		} else {
			if (s[0] == 'a') puts("ba");
			else puts("NO");
		}
		return 0;
	}
	for (int a = N; a--; ) {
		c = s[a] + 1;
		while ((a-2 >= 0 && c == s[a-2]) ||
				(a-1 >= 0 && c == s[a-1])) c++;
		if (c >= 'a' + P) continue;
		fo(i, a+1, N) {
			s[i] = 'a';
			while ((i-2 >= 0 && s[i] == s[i-2]) ||
					(i-1 >= 0 && s[i] == s[i-1])) s[i]++;
			assert(s[i] < 'a' + P);
		}
		s[a] = c;
		assert(s[a] < 'a' + P);
		cout << s << endl;
		return 0;
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define MT make_tuple
#define PB push_back
typedef long long ll;

int N, P;
string s;
char c;

int main () {
	cin >> N >> P >> s;
	if (P == 1) return puts("NO"), 0;
	if (P == 2) {
		if (N == 1) puts("b");
		else puts("ba");
		return 0;
	}
	for (int a = N; a--; ) {
		c = s[a] + 1;
		while ((a-2 >= 0 && c == s[a-2]) ||
				(a-1 >= 0 && c == s[a-1])) c++;
		if (c >= 'a' + P) continue;
		fo(i, a+1, N) {
			s[i] = 'a';
			while ((i-2 >= 0 && s[i] == s[i-2]) ||
					(i-1 >= 0 && c == s[i-1])) s[i]++;
		}
		s[a] = c;
		cout << s << endl;
		return 0;
	}
	puts("NO");
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1010];
int ind=0;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,p,i,j,k,l,m;
	cin>>n>>p;
	cin>>str;
	for (i=n-1;i>=0;i--)
	{
		k=str[i]-'a';
		for (j=k+1;j<p;j++)
		{
			char ch=(char)(j+97);
			//cout<<ch<<endl;
			if ((i>0 && str[i-1]==ch) || (i>1 && str[i-2]==ch))
			continue;
			//cout<<ch<<"$$"<<endl;
			str[i]=ch;
			ind=i+1;
			break;
		}
		if (ind)
		break;
	}
	l=0;i=ind;
		if ((i>0 && str[i-1]=='a') || (i>1 && str[i-2]=='a'))
		{
				if ((i>0 && str[i-1]=='b') || (i>1 && str[i-2]=='b'))
				l=2;
				else
				l=1;
		}
		else
		l=0;
	for (i=ind;i<n;i++)
	{
		char ch=(char)l+97;
		str[i]=ch;
		l++;
		if (l>=3)
		l%=3;
	}
	if (!ind)
	cout<<"NO\n";
	else{
//	cout<<"YES\n";
	cout<<str;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1010];
int ind=0;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,p,i,j,k,l,m;
	cin>>n>>p;
	cin>>str;
	for (i=n-1;i>=0;i--)
	{
		k=str[i]-'a';
		for (j=k+1;j<p;j++)
		{
			char ch=(char)(j+97);
			//cout<<ch<<endl;
			if ((i>0 && str[i-1]==ch) || (i>1 && str[i-2]==ch))
			continue;
			//cout<<ch<<"$$"<<endl;
			str[i]=ch;
			ind=i+1;
			break;
		}
		if (ind)
		break;
	}
	for (i=ind;i<n;i++)
	{
		for (l=0;l<3;l++){
		char ch=(char)l+97;
			if ((i>0 && str[i-1]==ch) || (i>1 && str[i-2]==ch))
			continue;
		str[i]=ch;
		break;
		}
	}
	if (!ind)
	cout<<"NO\n";
	else{
//	cout<<"YES\n";
	cout<<str;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1010];
int ind=0;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,p,i,j,k,l,m;
	cin>>n>>p;
	cin>>str;
	for (i=n-1;i>=0;i--)
	{
		k=str[i]-'a';
		for (j=k+1;j<p;j++)
		{
			char ch=(char)(j+97);
			//cout<<ch<<endl;
			if ((i>0 && str[i-1]==ch) || (i>1 && str[i-2]==ch))
			continue;
			//cout<<ch<<"$$"<<endl;
			str[i]=ch;
			ind=i+1;
			break;
		}
		if (ind)
		break;
	}
	l=0;
	for (i=ind;i<n;i++)
	{
		char ch=(char)l+97;
		str[i]=ch;
		l++;
		if (l>=3)
		l%=3;
	}
	if (!ind)
	cout<<"NO\n";
	else{
	cout<<"YES\n";
	cout<<str;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
char str[1010];
int ind=0;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,p,i,j,k,l,m;
	cin>>n>>p;
	cin>>str;
	for (i=n-1;i>=0;i--)
	{
		k=str[i]-'a';
		for (j=k+1;j<p;j++)
		{
			char ch=(char)(j+97);
			//cout<<ch<<endl;
			if ((i>0 && str[i-1]==ch) || (i>1 && str[i-2]==ch))
			continue;
			//cout<<ch<<"$$"<<endl;
			str[i]=ch;
			ind=i+1;
			break;
		}
		if (ind)
		break;
	}
	l=0;
	for (i=ind;i<n;i++)
	{
		char ch=(char)l+97;
		str[i]=ch;
		l++;
		if (l>=3)
		l%=3;
	}
	if (!ind)
	cout<<"NO\n";
	else{
//	cout<<"YES\n";
	cout<<str;
	}
	return 0;
}


#include <bits/stdc++.h>

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

#define ll long long
#define pb push_back
#define  mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second
#define nl "\n"

#define EPS 1e-8
#define OO 100000000

#define on(i,n) i=i|(1<<n)
#define off(i,n) i=i& (~(1<<n))

using namespace std;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    if(s[idx]!=prev && s[idx]!=prevprev){
    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if((comp(curr2,idx)|| done) && curr2.back()!='z'+1)
        curr=curr2;

   // cout<<curr2<<endl;
    }
    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx]+1;
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if((comp(nw,idx)|| done) && nw.back()!='z'+1){
        curr=min(curr,nw);
        break;
        }

    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
    p=f('z'+1,'z'+1,0,0);

    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <iostream>
#include <cstdio>
#include<unordered_map>
#include<unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include<cassert>
#include <set>
#include<sstream>
#include<iomanip>
#include<numeric>
#include <climits>
#include<string>

#define PI acos(-1)
#define mp make_pair
#define pb push_back
#define eps 1e-9
#define fi first
#define se second
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("input.txt", "r", stdin),freopen ("output.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define lp(i,n) for(int i=0; i<n; i++)
//#define mid ((st + en) >> 1)

using namespace std;

typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<vector<long long> > matrix;
typedef pair<pii, int> piii;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if(comp(curr2,idx)) curr=curr2;

    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx]+1;
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if(comp(nw,idx))
        curr=min(curr,nw);
    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
p=f('}','}',0,0);

    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <iostream>
#include <cstdio>
#include<unordered_map>
#include<unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include<cassert>
#include <set>
#include<sstream>
#include<iomanip>
#include<numeric>
#include <climits>
#include<string>

#define PI acos(-1)
#define mp make_pair
#define pb push_back
#define eps 1e-9
#define fi first
#define se second
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("input.txt", "r", stdin),freopen ("output.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define lp(i,n) for(int i=0; i<n; i++)
//#define mid ((st + en) >> 1)

using namespace std;

typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<vector<long long> > matrix;
typedef pair<pii, int> piii;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if(comp(curr2,idx)) curr=curr2;

    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx];
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if(comp(nw,idx))
        curr=min(curr,nw);
    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
p=f('}','}',0,0);

    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <bits/stdc++.h>

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

#define ll long long
#define pb push_back
#define  mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second
#define nl "\n"

#define EPS 1e-8
#define OO 100000000

#define on(i,n) i=i|(1<<n)
#define off(i,n) i=i& (~(1<<n))

using namespace std;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    if(s[idx]!=prev && s[idx]!=prevprev){
    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if((comp(curr2,idx)|| done) && curr2.back()!='z'+1)
        curr=curr2;

   // cout<<curr2<<endl;
    }
    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx]+1;
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if((comp(nw,idx)|| done) && nw.back()!='z'+1){
        curr=min(curr,nw);
        break;
        }

    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
    p=f('z'+1,'z'+1,0,0);

    cout<<p<<endl;
    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <bits/stdc++.h>

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

#define ll long long
#define pb push_back
#define  mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second
#define nl "\n"

#define EPS 1e-8
#define OO 100000000

#define on(i,n) i=i|(1<<n)
#define off(i,n) i=i& (~(1<<n))

using namespace std;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    if(s[idx]!=prev && s[idx]!=prevprev){
    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if((comp(curr2,idx)|| done) && curr2.back()!='z'+1)
        curr=curr2;

   // cout<<curr2<<endl;
    }
    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx]+1;
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if((comp(nw,idx)|| done) && nw.back()!='z'+1)
        curr=min(curr,nw);
    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
    p=f('z'+1,'z'+1,0,0);

    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <bits/stdc++.h>

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

#define ll long long
#define pb push_back
#define  mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second
#define nl "\n"

#define EPS 1e-8
#define OO 100000000

#define on(i,n) i=i|(1<<n)
#define off(i,n) i=i& (~(1<<n))

using namespace std;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    if(s[idx]!=prev && s[idx]!=prevprev){
    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if((comp(curr2,idx)|| done) && curr2.back()!='z'+1)
        curr=curr2;

   // cout<<curr2<<endl;
    }
    char c;
    if(done==true){
        c='a';
    }else{
        c=s[idx]+1;
    }
    for(; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if((comp(nw,idx)|| done) && nw.back()!='z'+1)
        curr=min(curr,nw);
    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
    p=f('z'+1,'z'+1,0,0);

    cout<<p<<endl;
    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <iostream>
#include <cstdio>
#include<unordered_map>
#include<unordered_set>
#include <algorithm>
#include <cstring>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cmath>
#include<cassert>
#include <set>
#include<sstream>
#include<iomanip>
#include<numeric>
#include <climits>
#include<string>

#define PI acos(-1)
#define mp make_pair
#define pb push_back
#define eps 1e-9
#define fi first
#define se second
#define endl '\n'
#define io  ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define file freopen ("input.txt", "r", stdin),freopen ("output.txt", "w", stdout);
#define filein freopen ("in.txt", "r", stdin);
#define all(v) ((v).begin()), ((v).end())
#define lp(i,n) for(int i=0; i<n; i++)
//#define mid ((st + en) >> 1)

using namespace std;

typedef long double ld;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef vector<vector<long long> > matrix;
typedef pair<pii, int> piii;

string s;
string dp[1000+5][26+10][26+10][2];
char n;
bool comp(string x,int idx){

    for(char c: x){

        if(c>s[idx]){
            return true;

        }
        idx++;
    }

    return false;

}

string f(char prev, char prevprev, bool done, int idx){

    if (idx==s.size()) return "";
    if(dp[idx][prev-'a'][prevprev-'a'][done]!="") return dp[idx][prev-'a'][prevprev-'a'][done];
    string curr(s.size()-idx,'z'+1);

    string curr2=s[idx]+f(s[idx],prev,done,idx+1);
    if(comp(curr2,idx)) curr=curr2;

    for(char c=s[idx]; c<=n; c++ ){
        if(c==prev || c==prevprev) continue;

        string nw=c+f(c,prev,true,idx+1);
        if(comp(nw,idx))
        curr=min(curr,nw);
    }

    return dp[idx][prev-'a'][prevprev-'a'][done]=curr;

}

int main(){
    int x;
    cin>>x;

    cin>>x;
    n=x+'a'-1;

  cin>>s;

    string p;
p=f('}','}',0,0);

    if(p.back()=='z'+1){

        cout<<"NO"<<endl;
    }else{
        cout<<p<<endl;
    }

}


#include <bits/stdc++.h>
#define N 1005
#define f(c,a,b) for(int c=a; c<=b; c++)
#define cl(a) max(0,a)

using namespace std;
int n, k;
char s[N]={0}, ans[N]={0};
char M;

bool p2(int i){
    f(j,i,n){
        bool flag = true;
        f(l,0,k){
            ans[j]=l+'a';
            //printf("ans[%d]=%c  ans[%d]=%c  ans[%d]=%c\n",j,ans[j],j-1,ans[j-1],j-2,ans[j-2]);
            if( (ans[j]!=ans[cl(j-1)])&&(ans[j]!=ans[cl(j-2)]) ) { flag=false; break; }
        }
        if(flag) return false;
    }
    return true;
}

bool work(){
    for (int i=n; i>=1; i--)
        for (char j=s[i]+1; j<=M; j++)
            if( (j!=s[cl(i-1)])&&(j!=s[cl(i-2)]) ) {
                ans[i] = j;
                ans[cl(i-1)] = s[cl(i-1)];
                if( p2(i+1) ) {
                    f(l,1,cl(i-2)) ans[l] = s[l];
                    return true;
                }
            }
    return false;
}

int main(){
    //freopen("owo.in","r",stdin);
    cin >> n >> k;
    if(k==1 && n==1) {
        cout<<"NO"<<endl;
        return 0;
    }
    if(k==2) {
        if(n==2){
            if(s[1]=='a') cout<<"ba"<<endl; else cout<<"NO"<<endl;
        }else{
            if(s[n]=='a') cout<<"b"<<endl; else cout<<"NO"<<endl;
        }
        return 0;
    }
    M = k-1+'a';
    scanf("%s", s+1);
    if( work() ) printf("%s", ans+1);
    else cout<<"NO"<<endl;
    return 0;
}


#include<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=2100;
int n,m;
char s[maxn],ans[maxn];
bool check(int x)
{
	if(x>=2&&s[x]==s[x-1])return 0;
	if(x>=3&&s[x]==s[x-2])return 0;
	return 1;
}
bool judge(int x)
{
	while(1)
	{
		if(x>n)return 1;
		if(x<=0)return 0;
		if(s[x]-'a'==m-1)
		{
			s[x]='a'-1;
			x--;
		}
		else
		{
			s[x]=(s[x]-'a'+1)%m+'a';
			if(check(x))x++;
		}
	}
	return 0;
}
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	int len=strlen(s+1);
	if(judge(len))printf("%s",s+1);
	else printf("NO");
	return 0;
}


#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<stack>
#include<bitset>
#include<deque>
#include<ctime>
#include<climits>
using namespace std;
#define LL long long
#define inf 0x3f3f3f3f
#define ri register int
#define il inline
#define fi first
#define se second
#define mp make_pair
#define pairint pair<int,int>
#define mem0(x) memset((x),0,sizeof (x))
#define mem1(x) memset((x),0x3f,sizeof (x))
#define gc getchar
template<class T>void in(T &x)
{
    x = 0;
    bool f = 0;
    char c = gc();
    while (c < '0' || c > '9')
    {
        if (c == '-') f = 1;
        c = gc();
    }
    while ('0' <= c && c <= '9')
    {
        x = (x << 3) + (x << 1) + (c ^ 48);
        c = gc();
    }
    if (f) x = -x;
}
#undef gc
#define pb push_back
#define N 1005
char s[N];
int n,p;
char can(int x)
{
	for(ri i=s[x]+1;i<='a'+p-1;++i)
		if(i!=s[x-1]&&i!=s[x-2]) return i;
	return 0;
}
signed main()
{
#ifdef M207
    freopen("in.in","r",stdin);
#endif
	in(n),in(p);
	scanf("%s",s+1);
	int pos=0;
	for(ri i=n;i>=1;--i)
	{
		if(can(i))
		{
			s[i]=can(i);
			pos=i;
			break;
		}
	}
	if(!pos)
	{
		puts("NO");
		return 0;
	}
	for(ri i=pos+1;i<=n;++i)
	{
		for(ri j='a';j<='a'+p-1;++j)
			if(j!=s[i-1]&&j!=s[i-2])
			{
				s[i]=j;
				break;
			}
	}
	for(ri i=1;i<=n;++i)
		putchar(s[i]);
    return 0;
}
//6498


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define mp make_pair
ll MOD=1000000007;
char a[100005]={};
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++)
	cin>>a[i];
	bool f=false;
	if(n>2&&d<=2)
	{
		cout<<"NO";
		return 0;
	}
	int index=n-1;
	for(int i=n-1;i>=0;i--)
	{	index=i;
		a[i]++;
		while((i>=1&&a[i]==a[i-1])||(i>=2&&a[i]==a[i-2]))
		{
			a[i]++;
		}
		if(int(a[i])<=int('a')+d-1)
		{
			break;
		}
	}
	if(a[index]<=int('a')+d-1)
	f=true;
	if(f==false)
	{cout<<"NO";
	return 0;}
	int x=int('a');
	int r=0;
	for(int i=index+1;i<n;i++)
	{
		char c=char(r+x);
		if(i>=1&&a[i-1]==c)
		{	c++;
			x++;
			x%=3;
		}
		if(i>=2&&a[i-2]==c)
		{
			c++;
			x++;
			x%=3;
		}
		a[i]=c;
		x++;
		x%=3;
	}
	for(int i=0;i<n;i++)
	cout<<a[i];
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define mp make_pair
ll MOD=1000000007;
char a[100005]={};
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++)
	cin>>a[i];
	bool f=false;
	if(d<=2)
	{
		cout<<"NO";
		return 0;
	}
	int index=n-1;
	for(int i=n-1;i>=0;i--)
	{	index=i;
		a[i]++;
		while((i>=1&&a[i]==a[i-1])||(i>=2&&a[i]==a[i-2]))
		{
			a[i]++;
		}
		if(int(a[i])<=int('a')+d-1)
		{
			break;
		}
	}
	if(a[index]<=int('a')+d-1)
	f=true;
	if(f==false)
	{cout<<"NO";
	return 0;}
	int x=int('a');
	int r=0;
	for(int i=index+1;i<n;i++)
	{
		char c=char(r+x);
		if(i>=1&&a[i-1]==c)
		{	c++;
			x++;
			x%=3;
		}
		if(i>=2&&a[i-2]==c)
		{
			c++;
			x++;
			x%=3;
		}
		a[i]=c;
		x++;
		x%=3;
	}
	for(int i=0;i<n;i++)
	cout<<a[i];
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define mp make_pair
ll MOD=1000000007;
char a[100005]={};
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++)
	cin>>a[i];
	bool f=false;
	if(n>2&&d<=2)
	{
		cout<<"NO";
		return 0;
	}
	int index=n-1;
	for(int i=n-1;i>=0;i--)
	{	index=i;
		a[i]++;
		while((i>=1&&a[i]==a[i-1])||(i>=2&&a[i]==a[i-2]))
		{
			a[i]++;
		}
		if(int(a[i])<=int('a')+d-1)
		{
			break;
		}
	}
	if(a[index]<=int('a')+d-1)
	f=true;
	if(f==false)
	{cout<<"NO";
	return 0;}
	int x=int('a');
	int r=0;
	for(int i=index+1;i<n;i++)
	{
		char c=char(r+x);
		if(i>=1&&a[i-1]==c)
		{	c++;
			r++;
			r%=3;
		}
		if(i>=2&&a[i-2]==c)
		{
			c++;
			r++;
			r%=3;
		}
		a[i]=c;
		r++;
		r%=3;
	}
	for(int i=0;i<n;i++)
	cout<<a[i];
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pp pop_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pss pair<string,string>
#define mp make_pair
ll MOD=1000000007;
char a[100005]={};
int main()
{
	std::ios::sync_with_stdio(false);
	ll n,d;
	cin>>n>>d;
	for(int i=0;i<n;i++)
	cin>>a[i];
	bool f=false;
	if(n>2&&d<=2)
	{
		cout<<"NO";
		return 0;
	}
	int index=n-1;
	for(int i=n-1;i>=0;i--)
	{	index=i;
		a[i]++;
		while((i>=1&&a[i]==a[i-1])||(i>=2&&a[i]==a[i-2]))
		{
			a[i]++;
		}
		if(int(a[i])<=int('a')+d-1)
		{
			break;
		}
	}
	if(a[index]<=int('a')+d-1)
	f=true;
	if(f==false)
	{cout<<"NO";
	return 0;}
	int x=int('a');
	int r=0;
	for(int i=index+1;i<n;i++)
	{
		char c=char(r+x);
		while((i>=1&&c==a[i-1])||(i>=2&&c==a[i-2]))
		{
			c++;
		}
		a[i]=c;
		r=0;
	//	r%=3;
	}
	for(int i=0;i<n;i++)
	cout<<a[i];
}


#include<bits/stdc++.h>

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int> > vvi;
#define forn(i,x,y) for(i = (x) ; i <= (y) ; ++i)
#define forr(i,y,x) for(i = (y) ; i >= (x) ; --i)
#define forv(v,i) for(i=v.begin();i!=v.end();++i)
#define forvr(v,i) for(i=v.end()-1;i!=v.begin();--i)
#define FA(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define MOD(x,y) (((x%M)*(y%M))%M)
#define CLR(x,y) memset(x,y,sizeof(x))
#define C(c) c-'a'

ll M=1e9+7;
// cout.fixed();
// cout.precision(10);
const double INF = 1e10;
//while(~scanf("%d",&n) )
/*-------------------------Template Ends--------------------------------*/

int main()
{
	ll n,p,i;
	string st;
	cin >> n >> p >> st;
	p += 'a' - 1;
	// cout << "p = " << p << endl;
	// cout << 'a' - 0 << endl;
	for(i = n-1; i > 1; --i) {
		int curr = st[i];
		// cout << "------------------- i = " << curr << endl;
		if(curr == p) continue;
		int next = curr + 1;
		// cout << "next = " << next << endl;
		if( (st[i-1] != next) and (st[i-2] != next) ) {
			st[i] = next;
			break;
		}
		if(next == p) continue;
		int snext = next + 1;
		// cout << "snext = " << snext << endl;
		if( (st[i-1] != snext) and (st[i-2] != snext) ) {
			st[i] = snext;
			break;
		}
		if(snext == p) continue;
		int tnext = snext + 1;
		st[i] = tnext; break;
	}

	if (i == 1) {
		int curr = st[i], next = st[i]+1;
		if( (curr < p) and (st[i-1] != next) ) {
			st[i] = next;
		} else --i;
	}
	if (i == 0) {
		int curr = st[i], next = st[i]+1;
		if( curr < p) {
			st[i] = next;
			--i;
		} else --i;
	}

	if(i < 0) {
		cout << "NO\n";
	} else {
		for(int j = i+1; j < n; ++j) {
			if( ((j-1 >= 0) and (st[j-1] != 'a')) and ((j-2 >= 0) and (st[j-2] != 'a')) ) st[j] = 'a';
			else if( ((j-1 >= 0) and (st[j-1] != 'b')) and ((j-2 >= 0) and (st[j-2] != 'b')) ) st[j] = 'b';
			else st[j] = 'c';
		}
		cout << st << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int> > vvi;
#define forn(i,x,y) for(i = (x) ; i <= (y) ; ++i)
#define forr(i,y,x) for(i = (y) ; i >= (x) ; --i)
#define forv(v,i) for(i=v.begin();i!=v.end();++i)
#define forvr(v,i) for(i=v.end()-1;i!=v.begin();--i)
#define FA(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define MOD(x,y) (((x%M)*(y%M))%M)
#define CLR(x,y) memset(x,y,sizeof(x))
#define C(c) c-'a'

ll M=1e9+7;
// cout.fixed();
// cout.precision(10);
const double INF = 1e10;
//while(~scanf("%d",&n) )
/*-------------------------Template Ends--------------------------------*/

int main()
{
	ll n,p,i;
	string st;
	cin >> n >> p >> st;
	p += 'a' - 1;
	for(i = n-1; i > 1; --i) {
		int curr = st[i];
		// cout << "------------------- i = " << i << endl;
		if(curr == p) continue;
		int next = curr + 1;
		// cout << "next = " << next << endl;
		if( (st[i-1] != next) and (st[i-2] != next) ) {
			st[i] = next;
			break;
		}
		if(next == p) continue;
		int snext = next + 1;
		// cout << "snext = " << snext << endl;
		if( (st[i-1] != snext) and (st[i-2] != snext) ) {
			st[i] = snext;
			break;
		}
		if(snext == p) continue;
		int tnext = snext + 1;
		st[i] = tnext; break;
	}

	if (i == 1) {
		// cout << "------------------- i = 1" << endl;
		int curr = st[i], next = st[i]+1;
		if( (curr < p) and (st[i-1] != next) ) {
			st[i] = next;
		} else if (next < p) {
			st[i] = ++next;
		} else --i;
	}
	if (i == 0) {
		// cout << "------------------- i = 0" << endl;
		int curr = st[i], next = st[i]+1;
		if( curr < p ) {
			st[i] = next;
		} else --i;
	}
	if((i < 0)) {
		cout << "NO\n";
	} else {
		for(int j = i+1; j < n; ++j) {
			if( j-2 >= 0 ) {
				if( st[j-1] != 'a' and st[j-2] != 'a' ) st[j] = 'a';
				else if( st[j-1] != 'b' and st[j-2] != 'b' ) st[j] = 'b';
				else st[j] = 'c';
			} else if ( j-1 >=0) {
				if( st[j-1] != 'a') st[j] = 'a';
				else if( st[j-1] != 'b') st[j] = 'b';
				else st[j] = 'c';
			}
		}
		cout << st << endl;
	}

	return 0;
}


#include<bits/stdc++.h>

using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<int> > vvi;
#define forn(i,x,y) for(i = (x) ; i <= (y) ; ++i)
#define forr(i,y,x) for(i = (y) ; i >= (x) ; --i)
#define forv(v,i) for(i=v.begin();i!=v.end();++i)
#define forvr(v,i) for(i=v.end()-1;i!=v.begin();--i)
#define FA(i, a) for (__typeof((a).begin()) i = (a).begin(); i != (a).end(); i++)
#define PB push_back
#define PF push_front
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define MOD(x,y) (((x%M)*(y%M))%M)
#define CLR(x,y) memset(x,y,sizeof(x))
#define C(c) c-'a'

ll M=1e9+7;
// cout.fixed();
// cout.precision(10);
const double INF = 1e10;
//while(~scanf("%d",&n) )
/*-------------------------Template Ends--------------------------------*/

int main()
{
	ll n,p,i;
	string st;
	cin >> n >> p >> st;
	p += 'a' - 1;
	for(i = n-1; i > 1; --i) {
		int curr = st[i];
		// cout << "------------------- i = " << curr << endl;
		if(curr == p) continue;
		int next = curr + 1;
		// cout << "next = " << next << endl;
		if( (st[i-1] != next) and (st[i-2] != next) ) {
			st[i] = next;
			break;
		}
		if(next == p) continue;
		int snext = next + 1;
		// cout << "snext = " << snext << endl;
		if( (st[i-1] != snext) and (st[i-2] != snext) ) {
			st[i] = snext;
			break;
		}
		if(snext == p) continue;
		int tnext = snext + 1;
		st[i] = tnext; break;
	}

	if (i == 1) {
		// cout << "------------------- i = 1" << endl;
		int curr = st[i], next = st[i]+1;
		if( (curr < p) and (st[i-1] != next) ) {
			st[i] = next;
		} else --i;
	}
	if (i == 0) {
		// cout << "------------------- i = 0" << endl;
		int curr = st[i], next = st[i]+1;
		if( curr < p) {
			st[i] = next;
		} else --i;
	}
	if((i < 0)) {
		cout << "NO\n";
	} else {
		for(int j = i+1; j < n; ++j) {
			if( j-2 >= 0 ) {
				if( st[j-1] != 'a' and st[j-2] != 'a' ) st[j] = 'a';
				else if( st[j-1] != 'b' and st[j-2] != 'b' ) st[j] = 'b';
				else st[j] = 'c';
			} else if ( j-1 >=0) {
				if( st[j-1] != 'a') st[j] = 'a';
				else if( st[j-1] != 'b') st[j] = 'b';
				else st[j] = 'c';
			}
		}
		cout << st << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair < int, int >

using namespace std;

int n, p;
string s;

int main(){
	#ifdef LOCAL
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
	#endif
	cin >> n >> p >> s;
	if (p == 1){
		cout << "NO";
		return 0;
	}
	if (p == 2){
		if (n >= 3)
			cout << "NO";
		else if (n == 1){
			if (s == "a")
				cout << "b";
			else
				cout << "NO";
		}
		else{
			if (s == "ab")
				cout << "ba";
			else
				cout << "NO";
		}
		return 0;
	}
	s = "#" + s;
	for (int i = n; i >= 1; i--){
		for (int j = s[i] + 1; j < 'a' + p; j++){
			bool ok = true;
			if (i - 1 >= 1 && s[i - 1] == j)
				ok = false;
			if (i - 2 >= 1 && s[i - 2] == j)
				ok = false;
			if (!ok)
				continue;
			for (int k = 1; k < i; k++)
				cout << s[k];
			cout << (char)j;
			s = "";
			if (j == 'a'){
				if ((i == 1) || (i - 1 >= 1 && s[i - 1] != 'b')){
					for (int i = 0; i < 500; i++)
						s += "bca";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cba";
				}
			}
			else if (j == 'b'){
				if ((i == 1) || (i - 1 >= 1 && s[i - 1] != 'a')){
					for (int i = 0; i < 500; i++)
						s += "acb";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cab";
				}
			}
			else{
				if ((i == 1) || (i - 1 >= 1 && s[i - 1] != 'a')){
					for (int i = 0; i < 500; i++)
						s += "abc";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "bac";
				}
			}
			n -= i;
			for (int i = 0; i < n; i++)
				cout << s[i];
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair < int, int >

using namespace std;

int n, p;
string s;

int main(){
	#ifdef LOCAL
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
	#endif
	cin >> n >> p >> s;
	s = "#" + s;
	if (p == 1){
		cout << "NO";
		return 0;
	}
	if (p == 2){
		if (n >= 3)
			cout << "NO";
		else if (n == 1){
			if (s == "a")
				cout << "b";
			else
				cout << "NO";
		}
		else{
			if (s == "ab")
				cout << "ba";
			else
				cout << "NO";
		}
		return 0;
	}
	for (int i = n; i >= 1; i--){
		for (int j = s[i] + 1; j < 'a' + p; j++){
			bool ok = true;
			if (i - 1 >= 1 && s[i - 1] == j)
				ok = false;
			if (i - 2 >= 1 && s[i - 2] == j)
				ok = false;
			if (!ok)
				continue;
			for (int k = 1; k < i; k++)
				cout << s[k];
			cout << (char)j;
			s = "";
			if (j == 'a'){
				if (i - 1 >= 1 && s[i - 1] != 'b'){
					for (int i = 0; i < 500; i++)
						s += "bca";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cba";
				}
			}
			else if (j == 'b'){
				if (i - 1 >= 1 && s[i - 1] != 'a'){
					for (int i = 0; i < 500; i++)
						s += "acb";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cab";
				}
			}
			else{
				if (i - 1 >= 1 && s[i - 1] != 'a'){
					for (int i = 0; i < 500; i++)
						s += "abc";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "bac";
				}
			}
			n -= i;
			for (int i = 0; i < n; i++)
				cout << s[i];
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include <bits/stdc++.h>

#define f first
#define s second
#define pb push_back
#define ll long long
#define mp make_pair
#define pii pair < int, int >

using namespace std;

int n, p;
string s;

int main(){
	#ifdef LOCAL
		freopen("in", "r", stdin);
		freopen("out", "w", stdout);
	#endif
	cin >> n >> p >> s;
	if (p == 1){
		cout << "NO";
		return 0;
	}
	if (p == 2){
		if (n >= 3)
			cout << "NO";
		else if (n == 1){
			if (s == "a")
				cout << "b";
			else
				cout << "NO";
		}
		else{
			if (s == "ab")
				cout << "ba";
			else
				cout << "NO";
		}
		return 0;
	}
	s = "#" + s;
	for (int i = n; i >= 1; i--){
		for (int j = s[i] + 1; j < 'a' + p; j++){
			bool ok = true;
			if (i - 1 >= 1 && s[i - 1] == j)
				ok = false;
			if (i - 2 >= 1 && s[i - 2] == j)
				ok = false;
			if (!ok)
				continue;
			for (int k = 1; k < i; k++)
				cout << s[k];
			cout << (char)j;
			s = "";
			if (j == 'a'){
				if (i - 1 >= 1 && s[i - 1] != 'b'){
					for (int i = 0; i < 500; i++)
						s += "bca";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cba";
				}
			}
			else if (j == 'b'){
				if (i - 1 >= 1 && s[i - 1] != 'a'){
					for (int i = 0; i < 500; i++)
						s += "acb";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "cab";
				}
			}
			else{
				if (i - 1 >= 1 && s[i - 1] != 'a'){
					for (int i = 0; i < 500; i++)
						s += "abc";
				}
				else{
					for (int i = 0; i < 500; i++)
						s += "bac";
				}
			}
			n -= i;
			for (int i = 0; i < n; i++)
				cout << s[i];
			return 0;
		}
	}
	cout << "NO";
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,mas[1005],rez[1005],aa;
string s,t;
char c;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    cin >> s;
    i=0;
    while (i<n)
    {
        c=s[i]-96;
        mas[i]=c;
        i++;
    }
    i=n-1;
    aa=0;
    while (i>=0&&aa==0)
    {
        j=mas[i]+1;
        while (j<=m&&aa==0)
        {
            if (mas[i-1]!=j&&mas[i-2]!=j)
            {
                rez[i]=j;
                aa=i+1;
            }
            j++;
        }
        i--;
    }
    if (aa>0)
    {
        aa--;
        i=0;
        while (i<aa)
        {
            cout << s[i];
            i++;
        }
        c=rez[aa]+96;
        cout << c;
        i=aa+1;
        while (i<n)
        {
            j=1;
            while (mas[i-1]==j||mas[i-2]==j)
            {
                j++;
            }
            c=j+96;
            cout << c;
            i++;
        }
    }
    else
    {
        cout << "NO";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,mas[1005],rez[1005],aa;
string s,t;
char c;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    cin >> s;
    i=0;
    while (i<n)
    {
        c=s[i]-96;
        mas[i]=c;
        i++;
    }
    i=n-1;
    aa=0;
    while (i>=0&&aa==0)
    {
        j=mas[i]+1;
        while (j<=m&&aa==0)
        {
            if (mas[i-1]!=j&&mas[i-2]!=j)
            {
                rez[i]=j;
                aa=i+1;
            }
            j++;
        }
        i--;
    }
    if (aa>0)
    {
        aa--;
        i=0;
        while (i<aa)
        {
            cout << s[i];
            i++;
        }
        c=rez[aa]+96;
        cout << c;
        i=aa+1;
        while (i<n)
        {
            j=1;
            while (mas[i-1]==j&&mas[i-2]==j)
            {
                j++;
            }
            c=j+96;
            cout << c;
            i++;
        }
    }
    else
    {
        cout << "NO";
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,mas[1005],rez[1005],aa;
string s,t;
char c;
int main()
{
    std::cin.sync_with_stdio(false);
    std::cin.tie(0);
    cin >> n >> m;
    cin >> s;
    i=0;
    while (i<n)
    {
        c=s[i]-96;
        mas[i]=c;
        i++;
    }
    i=n-1;
    aa=0;
    while (i>=0&&aa==0)
    {
        j=mas[i]+1;
        while (j<=m&&aa==0)
        {
            if (mas[i-1]!=j&&mas[i-2]!=j)
            {
                rez[i]=j;
                aa=i+1;
            }
            j++;
        }
        i--;
    }
    if (aa>0)
    {
        aa--;
        i=0;
        while (i<aa)
        {
            rez[i]=mas[i];
            cout << s[i];
            i++;
        }
        c=rez[aa]+96;
        cout << c;
        i=aa+1;
        while (i<n)
        {
            j=1;
            if (i>=2)
            {
                while (rez[i-1]==j||rez[i-2]==j)
                {
                    j++;
                }
            }
            if (i==1)
            {
                while (rez[i-1]==j)
                {
                    j++;
                }
            }
            rez[i]=j;
            c=j+96;
            cout << c;
            i++;
        }
    }
    else
    {
        cout << "NO";
    }
    return 0;
}


#include <iostream>

using namespace std;

const int NUM = 1050;

int n, p;
char S[NUM], T[NUM];

bool forward_ = true;

bool solve (int x) {

	// base case. The first time this gets called is because you want to start replacing the rightmost charcater.
	// The second time it gets here is when succeeds in filling S[i+1, ... , n-1] with a, b, c, ..., (up to p charcaters) without
	// creating a palindrome. That means, we have found the lexigorically next tolerable string (= answer!)
	if(x == n) {
		bool ret = !forward_;
		forward_ = false;
		return ret;
	}

	// in order to fill S[i+1, ..., n-1] with a, b, c, and get the lexigorically next possibly tolerable string,
	// you start with 'a'
	char replaceTo = 'a';

	// the first time going forward
	// copy S[x] into T[x] and set c to be S[x] + 1. This is because we want the lexigorically "next" possibly tolerable string.
	// can only increment. not decrement!
	if(forward_) {
		T[x] = S[x]; replaceTo = S[x] + 1;
		solve(x+1);
	}

	// brute force.
	// try incrementing the chracter up to the first p characters.
	for(; replaceTo < 'a'+ p; replaceTo++) {

		// for it to be tolerable, the incremented char must not form a panlindromic substring.
		if(x-1 >= 0 && T[x-1] == replaceTo) continue;
		if(x-2 >= 0 && T[x-2] == replaceTo) continue;

		T[x] = replaceTo;

		// once found a possible increment, recurse and try to fill the rest of the string S[x+1, ..., n-1] with a, b, c,... (up to p characters) w/o creating a palindromic substirng
		if(solve(x+1)) return 1;
	}

	// failed.
	return 0;
}

int main() {
	scanf("%d%d", &n, &p);
	scanf("%s", S);
	if (solve(0)) {
		cout << T << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <deque>
#include <utility>
#include <bitset>
#include <limits.h>
#include <iostream>

using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef double lf;
typedef unsigned int uint;
typedef long double llf;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int N_ = 1050;

int N, P;
char S[N_], T[N_];

bool first = true;
bool solve (int x) {
	if(x == N) {
		bool ret = !first;
		first = false;
		// cout << "hit the bottom.." << endl;
		// cout << ret << endl;
		return ret;
	}
	char c = 'a';
	if(first) {
		// cout << "gets in the if(first).." << endl;
		T[x] = S[x]; c = S[x] + 1;
		// cout << c << endl;
		if(solve(x+1)) return 1;
	}

	// cout << "about to enter the for loop.." << endl;
	for(; c < 'a'+P; c++) {
		// cout << "inside the for loop.." << c << endl;
		if(x-1 >= 0 && T[x-1] == c) continue;
		if(x-2 >= 0 && T[x-2] == c) continue;
		T[x] = c;
		if(solve(x+1)) return 1;
	}
	return 0;
}

int main() {
	scanf("%d%d%s", &N, &P, S);
	// sprintf(T, S);
	puts(solve(0) ? T : "NO");

	return 0;
}


#include <iostream>

using namespace std;

const int NUM = 1050;

int n, p;
char S[NUM], T[NUM];

bool forward_ = true;

bool solve (int x) {

	// base case. The first time this gets called is because you want to start replacing the rightmost charcater.
	// The second time it gets here is when succeeds in filling S[i+1, ... , n-1] with a, b, c, ..., (up to p charcaters) without
	// creating a palindrome. That means, we have found the lexigorically next tolerable string (= answer!)
	if(x == n) {
		bool ret = !forward_;
		forward_ = false;
		return ret;
	}

	// in order to fill S[i+1, ..., n-1] with a, b, c, and get the lexigorically next possibly tolerable string,
	// you start with 'a'
	char replaceTo = 'a';

	// the first time going forward
	// copy S[x] into T[x] and set c to be S[x] + 1. This is because we want the lexigorically "next" possibly tolerable string.
	// can only increment. not decrement!
	if(forward_) {
		T[x] = S[x]; replaceTo = S[x] + 1;
		if(solve(x+1)) return 1;
	}

	// brute force.
	// try incrementing the chracter up to the first p characters.
	for(; replaceTo < 'a'+ p; replaceTo++) {

		// for it to be tolerable, the incremented char must not form a panlindromic substring.
		if(x-1 >= 0 && T[x-1] == replaceTo) continue;
		if(x-2 >= 0 && T[x-2] == replaceTo) continue;

		T[x] = replaceTo;

		// once found a possible increment, recurse and try to fill the rest of the string S[x+1, ..., n-1] with a, b, c,... (up to p characters) w/o creating a palindromic substirng
		if(solve(x+1)) return 1;
	}

	// failed.
	return 0;
}

int main() {
	scanf("%d%d", &n, &p);
	scanf("%s", S);
	if (solve(0)) {
		cout << T << endl;
	} else {
		cout << "NO" << endl;
	}
	return 0;
}


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

// why am I so weak

int n, p;
char s[1055];

inline bool cool(int to) {
	for (int i = 0; i + 1 <= to; i++) {
		if (s[i] == s[i + 1]) {
			return false;
		}
	}

	for (int i = 0; i + 2 <= to; i++) {
		if (s[i] == s[i + 2]) {
			return false;
		}
	}

	return true;
}
int main() {
	scanf("%d %d", &n, &p);
	scanf("%s", s);

	for (int i = n - 1; i >= 0; i--) {
		for (char ch = s[i] + 1; ch < 'a' + p; ch++) {
			s[i] = ch;

			if (cool(i)) {
				bool bad = false;

				for (int j = i + 1; j < n; j++) {
					s[j] = '$';
					for (char to = 'a'; to < 'a' + p; to++) {
						if (j && to == s[j - 1]) continue;
						if (j - 2 >= 0 && to == s[j - 2]) continue;

						s[j] = to;
						break;
					}

					if (s[j] == '$') {
						bad = true;
						break;
					}
				}

				if (bad || !cool(n - 1)) {
					continue;
				}

				puts(s);

				return 0;
			}
		}
	}

	puts("NO");

	return 0;
}


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

// why am I so weak

int n, p;
char s[1055];

inline bool cool(int to) {
	for (int i = 0; i + 1 <= to; i++) {
		if (s[i] == s[i + 1]) {
			return false;
		}
	}

	for (int i = 0; i + 2 <= to; i++) {
		if (s[i] == s[i + 2]) {
			return false;
		}
	}

	return true;
}
int main() {
	scanf("%d %d", &n, &p);
	scanf("%s", s);

	for (int i = n - 1; i >= 0; i--) {
		for (char ch = s[i] + 1; ch < 'a' + p; ch++) {
			s[i] = ch;

			if (cool(i)) {
				int cur = ch - 'a';

				for (int j = i + 1; j < n; j++) {
					cur = (cur + 1) % p;
					s[j] = 'a' + cur;
				}

				if (!cool(n - 1)) {
					for (int j = i + 1; j < n; j++) {
						s[j] = '$';
					}
					continue;
				}

				puts(s);

				return 0;
			}
		}

		s[i] = '$';
	}

	puts("NO");

	return 0;
}


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

// why am I so weak

int n, p;
char s[1055];

inline bool cool(int to) {
	for (int i = 0; i + 1 <= to; i++) {
		if (s[i] == s[i + 1]) {
			return false;
		}
	}

	for (int i = 0; i + 2 <= to; i++) {
		if (s[i] == s[i + 2]) {
			return false;
		}
	}

	return true;
}
int main() {
	scanf("%d %d", &n, &p);
	scanf("%s", s);

	for (int i = n - 1; i >= 0; i--) {
		for (char ch = s[i] + 1; ch < 'a' + p; ch++) {
			s[i] = ch;

			if (cool(i)) {
				bool bad = false;

				for (int j = i + 1; j < n; j++) {
					s[j] = '$';
					for (char to = 'a'; to < 'a' + p; to++) {
						if (j && to == s[j - 1]) continue;
						if (j - 2 && to == s[j - 2]) continue;

						s[j] = to;
						break;
					}

					if (s[j] == '$') {
						bad = true;
						break;
					}
				}

				if (bad || !cool(n - 1)) {
					continue;
				}

				puts(s);

				return 0;
			}
		}
	}

	puts("NO");

	return 0;
}


/*
By Tianyi Chen. All rights reserved.
Date: 2016-07-17
*/
#include<bits/stdc++.h>
using namespace std;
int n,p;
char buf[1001];
bool ans;
char inc(char v,int pos) {
 while (++v<p+'a') {
  if (pos&&buf[pos-1]==v||pos>=2&&buf[pos-2]==v)continue;
  else return v;
 }
 return 0;
}
int main() {
 scanf("%d%d",&n,&p);scanf("%s",buf);
 if (p==2&&*buf<1[buf])return swap(*buf,1[buf]),puts(buf),0;
 if (p<3)return puts("NO"),0;
 for(int i=n-1;i>=0;--i) {
  char c=inc(buf[i],i);
  if (c) {
   ans=1;
   buf[i]=c;
   for(int j=i+1;j<n;++j)buf[j]=inc('a'-1,j);
   break;
  }
 }
 puts(ans?buf:"NO");
}


/*
By Tianyi Chen. All rights reserved.
Date: 2016-07-17
*/
#include<bits/stdc++.h>
using namespace std;
int n,p;
char buf[1001];
bool ans;
char inc(char v,int pos) {
 while (++v<p+'a') {
  if (pos&&buf[pos-1]==v||pos>=2&&buf[pos-2]==v)continue;
  else return v;
 }
 return 0;
}
int main() {
 scanf("%d%d",&n,&p);scanf("%s",buf);
 if (p<3)return puts("NO"),0;
 for(int i=n-1;i>=0;--i) {
  char c=inc(buf[i],i);
  if (c) {
   ans=1;
   buf[i]=c;
   for(int j=i+1;j<n;++j)buf[j]=inc('a'-1,j);
   break;
  }
 }
 puts(ans?buf:"NO");
}


/*
By Tianyi Chen. All rights reserved.
Date: 2016-07-17
*/
#include<bits/stdc++.h>
using namespace std;
int n,p;
char buf[1001];
bool ans;
char inc(char v,int pos) {
 while (++v<p+'a') {
  if (pos&&buf[pos-1]==v||pos>=2&&buf[pos-2]==v)continue;
  else return v;
 }
 return 0;
}
int main() {
 scanf("%d%d",&n,&p);scanf("%s",buf);
 if (p==1)return puts("NO"),0;
 if (p==2)return swap(*buf,1[buf]),puts(buf),0;
 for(int i=n-1;i>=0;--i) {
  char c=inc(buf[i],i);
  if (c) {
   ans=1;
   buf[i]=c;
   for(int j=i+1;j<n;++j)buf[j]=inc('a'-1,j);
   break;
  }
 }
 puts(ans?buf:"NO");
}


/*
By Tianyi Chen. All rights reserved.
Date: 2016-07-17
*/
#include<bits/stdc++.h>
using namespace std;
int n,p;
char buf[1001];
bool ans;
char inc(char v,int pos) {
 while (++v<p+'a') {
  if (pos&&buf[pos-1]==v||pos>=2&&buf[pos-2]==v)continue;
  else return v;
 }
 return 0;
}
int main() {
 scanf("%d%d",&n,&p);scanf("%s",buf);
 for(int i=n-1;i>=0;--i) {
  char c=inc(buf[i],i);
  if (c) {
   ans=1;
   buf[i]=c;
   for(int j=i+1;j<n;++j)buf[j]=inc('a'-1,j);
   break;
  }
 }
 puts(ans?buf:"NO");
}


/*
By Tianyi Chen. All rights reserved.
Date: 2016-07-17
*/
#include<bits/stdc++.h>
using namespace std;
int n,p;
char buf[1001];
bool ans;
char inc(char v,int pos) {
 while (++v<p+'a') {
  if (pos&&buf[pos-1]==v||pos>=2&&buf[pos-2]==v)continue;
  else return v;
 }
 return 0;
}
int main() {
 scanf("%d%d",&n,&p);scanf("%s",buf);
 if (p==2&&*buf<1[buf])return swap(*buf,1[buf]),puts(buf),0;
 if (p==1&&++*buf<p+'a')return puts(buf),0;
 if (p<3)return puts("NO"),0;
 for(int i=n-1;i>=0;--i) {
  char c=inc(buf[i],i);
  if (c) {
   ans=1;
   buf[i]=c;
   for(int j=i+1;j<n;++j)buf[j]=inc('a'-1,j);
   break;
  }
 }
 puts(ans?buf:"NO");
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<SZ(s);i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        { cout<<"NO"; return 0; }

    while(s[0]-'a'<p-1)
    {
        int e=n-1;
        while(e>0 && s[e]-'a'>=p-1)
            s[e]='a',e--, s[e]++;
        s[n-1]++;

        if(s[0]-'a'<p-1 && isContainPali())
            { cout<<s; return 0; }
    }

    cout<<"NO";
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<n;i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

int main()
{
    cin>>n>>p>>s; s+='.';
    if(!valid())
        { cout<<"NO"; return 0; }

    s[n-1]++;
    while(s[0]-'a'<=p-1)
    {
        int e=n-1;
        bool isPali=0;

        while(e>0 && s[e]-'a'>p-1)
            s[e]='a',e--, s[e]++,
            isPali|=(s[e+1]==s[e]|s[e+2]==s[e]);

        if(s[0]-'a'<=p-1 && !isPali)
            { s[SZ(s)-1]='\0'; cout<<s; return 0; }
        s[n-1]++;
    }

    cout<<"NO";
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<SZ(s);i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        { cout<<"NO"; return 0; }

    while(s[0]-'a'>=p-1)
    {
        int e=n-1;
        while(e>0 && s[e]-'a'>=p-1)
            s[e]='a',e--, s[e]++;
        s[n-1]++;

        if(s[0]-'a'<p-1 && isContainPali())
            { cout<<s; return 0; }
    }

    cout<<"NO";
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<n;i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

bool DFS(int i,int e)
{
    if(i==n)
        return e;

    char a=e?'a':s[i];
    char b='a'+p-1;

    for(char x=a;x<=b;x++)
    {
        char prv=s[i]; s[i]=x;
        if( (i>0&&s[i]==s[i-1]) || (i>1&&s[i]==s[i-2]) )
            continue;
        if( DFS(i+1,e||x>prv) )
            return 1;
    }

    return 0;
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        cout<<"NO";
    else
        cout<<( DFS(0,0)? s:"NO" );
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<n;i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

bool DFS(int i,int e)
{
    if(i==n)
        return e;

    char a=e?'a':s[i];
    char b='a'+p-1;

    for(char x=a;x<=b;x++)
    {
        s[i]=x;
        if( (i>1&&s[i]==s[i-1]) || (i>2&&s[i]==s[i-2]) )
            continue;
        if( DFS(i+1,e||x>s[i]) )
            return 1;
    }

    return 0;
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        cout<<"NO";
    else
        cout<<( DFS(0,0)? "YES":"NO" );
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<SZ(s);i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        { cout<<"NO"; return 0; }

    int e=n-1;
    while(e>0)
    {
        e=n-1;
        while(e>0 && s[e]-p>='a'-1)
            s[e]='a',e--;
        s[n-1]++;

        if(isContainPali())
            { cout<<s; return 0; }
    }

    cout<<"NO";
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<SZ(s);i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        { cout<<"NO"; return 0; }

    s[n-1]++;
    while(s[0]-'a'<=p-1)
    {
        int e=n-1;
        while(e>0 && s[e]-'a'>p-1)
            s[e]='a',e--, s[e]++;

        if(s[0]-'a'<=p-1 && isContainPali())
            { cout<<s; return 0; }
        s[n-1]++;
    }

    cout<<"NO";
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<n;i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

bool DFS(int i,int e)
{
    if(i==n)
        return e;

    char a=e?'a':s[i];
    char b='a'+p-1;

    for(char x=a;x<=b;x++)
    {
        char prv=s[i]; s[i]=x;
        if( (i>1&&s[i]==s[i-1]) || (i>2&&s[i]==s[i-2]) )
            continue;
        if( DFS(i+1,e||x>prv) )
            return 1;
    }

    return 0;
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        cout<<"NO";
    else
        cout<<( DFS(0,0)? "YES":"NO" );
}


#include <bits/stdc++.h>
#define SZ(x) (int)x.size()
typedef long long ll;
const int SZ=1e3+5;
#define X first
#define Y second
using namespace std;

int n,p;
string s;

bool isContainPali()
{
    for(int i=0;i<n;i++)
    {
        if(i+1<n && s[i]==s[i+1]) return false;
        if(i+2<n && s[i]==s[i+2]) return false;
    }
    return true;
}

bool valid()
{
    for(int i=0;i<n;i++)
        if(s[i]-'a'>=p)
            return false;

    return isContainPali();
}

bool DFS(int i,int e)
{
    if(i==n)
        return e;

    char a=e?'a':s[i];
    char b='a'+p-1;

    for(char x=a;x<=b;x++)
    {
        s[i]=x;
        if( (i>1&&s[i]==s[i-1]) || (i>2&&s[i]==s[i-2]) )
            continue;
        if( DFS(i+1,e||x>s[i]) )
            return 1;
    }
}

int main()
{
    cin>>n>>p>>s;
    if(!valid())
        cout<<"NO";
    else
        cout<<( DFS(0,0)? "YES":"NO" );
}


#include <bits/stdc++.h>

using namespace std;

int n,m,k;
string s;

int main (){
	cin >> n >> k >> s;
	if (k == 1) {
		cout << "NO";
		return 0;
	}
	if (k == 2){
		if (n == 1){
			if (s == "a") cout << 'b';
			else cout << "NO";
		}
		else if (n == 2){
			if (s == "ab") cout << "ba";
			else cout << "NO";
		}
		else cout << "NO";
		return 0;
	}
	int ot = -1;
	for (int i = s.size() - 1; i >= 0; i--){
		int bb = 0;
		while (1){
			s[i]++;
			if (s[i] >= 'a' + k) break;
			if ((!i || s[i] != s[i - 1]) && (i <= 1 || s[i] != s[i - 2])){
				ot = i;
				bb = 1;
				break;
			}
		}
		if (bb) break;
	}
	if (ot == -1) {
		cout << "NO";
		return 0;
	}
	for (int i = ot + 1; i < s.size(); i++){
		if (s[i - 1] != 'a' && (i <= 1  || s[i - 2] != 'a')) s[i] = 'a';
		else if (s[i - 1] != 'b' && (i <= 1 || s[i - 2] != 'b')) s[i] = 'b';
		else s[i] = 'c';
	}
	cout << s;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,k;
string s;

int main (){
	cin >> n >> k >> s;
	if (k == 1) {
		cout << "NO";
		return 0;
	}
	if (k == 2){
		if (n == 1){
			if (s == "a") cout << 'b';
			else cout << "NO";
		}
		else if (n == 2){
			if (s == "ab") cout << "ba";
			else cout << "NO";
		}
		else cout << "NO";
		return 0;
	}
	int ot = -1;
	for (int i = s.size() - 1; i >= 0; i--){
		int bb = 0;
		while (1){
			s[i]++;
			if (s[i] >= 'a' + k) break;
			if ((!i || s[i] != s[i - 1]) && (i <= 1 && s[i] != s[i - 2])){
				ot = i;
				bb = 1;
				break;
			}
		}
		if (bb) break;
	}
	if (ot == -1) {
		cout << "NO";
		return 0;
	}
	for (int i = ot + 1; i < s.size(); i++){
		if (s[i - 1] != 'a' && (i > 2 || s[i - 2] != 'a')) s[i] = 'a';
		else if (s[i - 1] != 'b' && (i > 2 || s[i - 2] != 'b')) s[i] = 'b';
		else s[i] = 'c';
	}
	cout << s;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,k;
string s;

int main (){
	cin >> n >> k >> s;
	if (k == 1) {
		cout << "NO";
		return 0;
	}
	if (k == 2){
		if (n == 1){
			if (s == "a") cout << 'b';
			else cout << "NO";
		}
		else if (n == 2){
			if (s == "ab") cout << "ba";
			else cout << "NO";
		}
		else cout << "NO";
		return 0;
	}
	int ot = -1;
	for (int i = s.size() - 1; i >= 0; i--){
		int bb = 0;
		while (1){
			s[i]++;
			if (s[i] >= 'a' + k) break;
			if ((!i || s[i] != s[i - 1]) && (i > 1 && s[i] != s[i - 2])){
				ot = i;
				bb = 1;
				break;
			}
		}
		if (bb) break;

	}
	if (ot == -1) {
		cout << "NO";
		return 0;
	}
	for (int i = ot + 1; i < s.size(); i++){
		if (s[i - 1] != 'a' && (i > 2 || s[i - 2] != 'a')) s[i] = 'a';
		else if (s[i - 1] != 'b' && (i > 2 || s[i - 2] != 'b')) s[i] = 'b';
		else s[i] = 'c';
	}
	cout << s;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,m,k;
string s;

int main (){
	cin >> n >> k >> s;
	if (k == 1) {
		cout << "NO";
		return 0;
	}
	if (k == 2){
		if (n == 1){
			if (s == "a") cout << 'b';
			else cout << "NO";
		}
		else if (n == 2){
			if (s == "ab") cout << "ba";
			else cout << "NO";
		}
		else cout << "NO";
		return 0;
	}
	int ot = -1;
	for (int i = s.size() - 1; i >= 0; i--){
		int bb = 0;
		while (1){
			s[i]++;
			if (s[i] >= 'a' + k) break;
			if ((!i || s[i] != s[i - 1]) && (i <= 1 || s[i] != s[i - 2])){
				ot = i;
				bb = 1;
				break;
			}
		}
		if (bb) break;
	}
	if (ot == -1) {
		cout << "NO";
		return 0;
	}
	for (int i = ot + 1; i < s.size(); i++){
		if (s[i - 1] != 'a' && (i > 2 || s[i - 2] != 'a')) s[i] = 'a';
		else if (s[i - 1] != 'b' && (i > 2 || s[i - 2] != 'b')) s[i] = 'b';
		else s[i] = 'c';
	}
	cout << s;
	return 0;
}