#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

int main()
{
	n = read();
	p = read();
	string org;
	cin >> org;
	org = "$$" + org;

	for (int start = n + 1; start >= 2; start--)
	{
		s = org;
		s[start]++;
		while (s[start] == s[start - 1] || s[start] == s[start - 2]) s[start]++;
		if (s[start] == 'a' + p) continue;
		for (int i = start + 1; i < n + 2; i++)
		{
			s[i] = 'a';
			while (s[i] == s[i - 1] || s[i] == s[i - 2]) s[i]++;
		}
		cout << s.substr(2);
		return 0;
	}

	cout << "NO";

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

bool next()
{
	int at = n - 1;
	while (at >= 0 && s[at] == 'a' + p - 1) at--;
	if (at < 0) return false;
	s[at]++;
	for (int i = at + 1; i < n; i++)
	{
		s[i] = 'a';
	}
	return true;
}

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

int main()
{
	n = read();
	p = read();
	cin >> s;

	while (true)
	{
		if (!next())
		{
			cout << "NO";
			return 0;
		}
		if (legal()) break;
	}

	cout << s;

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

bool next()
{
	int at = n - 1;
	while (at >= 0 && s[at] == 'a' + p - 1) at--;
	if (at < 0) return false;
	s[at]++;
	for (int i = at + 1; i < n; i++)
	{
		s[i] = 'a';
	}
	return true;
}

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

int main()
{
	n = read();
	p = read();
	string org;
	cin >> org;
	s = org;

	if (!next())
	{
		cout << "NO";
		return 0;
	}
	s = "$" + s;
	bool tomin = false;
	for (int i = 2; i <= n; i++)
	{
		if (tomin)
		{
			s[i] = 'a';
		}
		while (s[i] == s[i - 2] || s[i] == s[i - 1])
		{
			s[i]++;
			if (s[i] == 'a' + p)
			{
				s[i] = 'a';
				tomin = true;
			}
		}
	}

	s = s.substr(1);
	if (!legal() || s <= org)
	{
		cout << "NO";
		return 0;
	}
	cout << s;

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

bool next()
{
	int at = n - 1;
	while (at >= 0 && s[at] == 'a' + p - 1) at--;
	if (at < 0) return false;
	s[at]++;
	for (int i = at + 1; i < n; i++)
	{
		s[i] = 'a';
	}
	return true;
}

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

int main()
{
	n = read();
	p = read();
	cin >> s;

	if (!next())
	{
		cout << "NO";
		return 0;
	}
	string res = "$" + s;
	bool tomin = false;
	for (int i = 2; i < n; i++)
	{
		if (tomin)
		{
			s[i] = 'a';
		}
		while (s[i] == s[i - 2] || s[i] == s[i - 1])
		{
			s[i]++;
			if (s[i] == 'a' + p)
			{
				s[i] = 'a';
				tomin = true;
			}
		}
	}

	s = res.substr(1);
	if (!legal())
	{
		cout << "NO";
		return 0;
	}
	cout << s;

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

bool next()
{
	int at = n - 1;
	while (at >= 0 && s[at] == 'a' + p - 1) at--;
	if (at < 0) return false;
	s[at]++;
	for (int i = at + 1; i < n; i++)
	{
		s[i] = 'a';
	}
	return true;
}

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

int main()
{
	n = read();
	p = read();
	cin >> s;

	if (!next())
	{
		cout << "NO";
		return 0;
	}
	s = "$" + s;
	bool tomin = false;
	for (int i = 2; i <= n; i++)
	{
		if (tomin)
		{
			s[i] = 'a';
		}
		while (s[i] == s[i - 2] || s[i] == s[i - 1])
		{
			s[i]++;
			if (s[i] == 'a' + p)
			{
				s[i] = 'a';
				tomin = true;
			}
		}
	}

	s = s.substr(1);
	if (!legal())
	{
		cout << "NO";
		return 0;
	}
	cout << s;

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <stdio.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cctype>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cassert>

using namespace std;

typedef long long ll;
typedef double real;
typedef pair<int, int> ii;

template <typename T>
string toString(T x)
{
	if (x == 0) return "0";
	bool negative = x < 0;
	string res;
	while (x)
	{
		res.push_back('0' + x % 10);
		x /= 10;
	}
	if (negative) res.push_back('-');
	reverse(res.begin(), res.end());
	return res;
}

void ioFromFile(string inputFileName, string outputFileName)
{
	ifstream fin(inputFileName);
	ofstream fout(outputFileName);
	cin.rdbuf(fin.rdbuf());
	cout.rdbuf(fout.rdbuf());
}

int read() { int res; scanf("%d", &res); return res; }
void write(int x) { printf("%d ", x); }

template <typename T>
T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
//---------------------------------------------------

int n, p;
string s;

int main()
{
	n = read();
	p = read();
	string org;
	cin >> org;
	org = "$$" + org;

	for (int start = n + 1; start >= 2; start--)
	{
		s = org;
		s[start]++;
		while (s[start] == s[start - 1] || s[start] == s[start - 2]) s[start]++;
		if (s[start] == 'a' + p) continue;
		for (int i = start; i < n + 2; i++)
		{
			s[i] = 'a';
			while (s[i] == s[i - 1] || s[i] == s[i - 2]) s[i]++;
		}
		cout << s.substr(2);
		return 0;
	}

	cout << "NO";

	return 0;
}

/*

5 99
aaaaa
2 .
4 .
3 .

*/


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int length, max_alphabet;
    cin >> length >> max_alphabet;

    string S;
    cin >> S;

    const int NOT_FOUND = -1;
    int first_greater_position = NOT_FOUND;
    char replacement;

    for(int i = length - 1; first_greater_position == NOT_FOUND && i >= 0; i--)
    {
        for(char new_ch = S[i] + 1; new_ch <= 'a' + max_alphabet - 1; new_ch++)
        {
            int possible = true;
            for(int j = i - 1; j >= max(i - 2, 0); j--)
            {
                if(new_ch == S[j])
                    possible = false;
            }

            if(possible)
            {
                first_greater_position = i;
                replacement = new_ch;
                break;
            }
        }
    }

    if(first_greater_position == NOT_FOUND)
    {
        cout << "NO\n";
        return 0;
    }

    string next_good_string;
    for(int i = 0 ; i < first_greater_position; i++)
        next_good_string += S[i];

    next_good_string += replacement;

    for(int i = first_greater_position + 1; i < length; i++)
    {
        char current_char;

        for(current_char = 'a'; current_char <= 'c'; current_char++)
        {
            if( (i - 1 >= 0 && next_good_string[i - 1] == current_char) ||
                (i - 2 >= 0 && next_good_string[i - 2] == current_char) )
            {
                continue;
            }
            else
            {
                next_good_string += current_char;
                break;
            }
        }
    }

    cout << next_good_string;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int length, max_alphabet;
    cin >> length >> max_alphabet;

    string S;
    cin >> S;

    if(max_alphabet == 1)
    {
        cout << (length == 1 ? S : "NO\n");
        return 0;
    }
    else if(max_alphabet == 2)
    {
        cout << (length <= 2 ? S : "NO\n");
        return 0;
    }

    const int NOT_FOUND = -1;
    int first_greater_position = NOT_FOUND;
    char replacement;

    for(int i = length - 1; first_greater_position == NOT_FOUND && i >= 0; i--)
    {

        for(char new_ch = S[i] + 1; new_ch <= 'a' + max_alphabet - 1; new_ch++)
        {
            int possible = true; //cout << "i = " << i << " " << new_ch << endl;
            for(int j = i - 1; j >= max(i - 2, 0); j--)
            {
                if(new_ch == S[j])
                    possible = false;
            }

            if(possible)
            { //cout << "i = " << i << endl;
                first_greater_position = i;
                replacement = new_ch;
                break;
            }
        }
    } //cout << replacement << " " << first_greater_position << endl;

    if(first_greater_position == NOT_FOUND)
    {
        cout << "NO\n";
        return 0;
    }

    string next_good_string;
    for(int i = 0 ; i < first_greater_position; i++)
        next_good_string += S[i];

    next_good_string += replacement;

    for(int i = first_greater_position + 1; i < length; i++)
    {
        char current_char;

        for(current_char = 'a'; current_char <= 'c'; current_char++)
        {
            if( (i - 1 >= 0 && next_good_string[i - 1] != current_char) &&
                (i - 2 >= 0 && next_good_string[i - 2] != current_char) )
            {
                break;
            }
        }

        next_good_string += current_char;
    }

    cout << next_good_string;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int length, max_alphabet;
    cin >> length >> max_alphabet;

    string S;
    cin >> S;

    if( (max_alphabet == 1 && length > 1) || (max_alphabet == 2 && length > 2) )
    {
        cout << "NO\n";
        return 0;
    }

    const int NOT_FOUND = -1;
    int first_greater_position = NOT_FOUND;
    char replacement;

    for(int i = length - 1; first_greater_position == NOT_FOUND && i >= 0; i--)
    {

        for(char new_ch = S[i] + 1; new_ch <= 'a' + max_alphabet - 1; new_ch++)
        {
            int possible = true; //cout << "i = " << i << " " << new_ch << endl;
            for(int j = i - 1; j >= max(i - 2, 0); j--)
            {
                if(new_ch == S[j])
                    possible = false;
            }

            if(possible)
            { //cout << "i = " << i << endl;
                first_greater_position = i;
                replacement = new_ch;
                break;
            }
        }
    } //cout << replacement << " " << first_greater_position << endl;

    if(first_greater_position == NOT_FOUND)
    {
        cout << "NO\n";
        return 0;
    }

    string next_good_string;
    for(int i = 0 ; i < first_greater_position; i++)
        next_good_string += S[i];

    next_good_string += replacement;

    for(int i = first_greater_position + 1; i < length; i++)
    {
        char current_char;

        for(current_char = 'a'; current_char <= 'c'; current_char++)
        {
            if( (i - 1 >= 0 && next_good_string[i - 1] == current_char) ||
                (i - 2 >= 0 && next_good_string[i - 2] == current_char) )
            {
                continue;
            }
            else
            {
                next_good_string += current_char;
                break;
            }
        }

       // next_good_string += current_char;
    }

    cout << next_good_string;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int length, max_alphabet;
    cin >> length >> max_alphabet;

    string S;
    cin >> S;

    if( (max_alphabet == 1 && length > 1) || (max_alphabet == 2 && length > 2) )
    {
        cout << "NO\n";
        return 0;
    }

    const int NOT_FOUND = -1;
    int first_greater_position = NOT_FOUND;
    char replacement;

    for(int i = length - 1; first_greater_position == NOT_FOUND && i >= 0; i--)
    {

        for(char new_ch = S[i] + 1; new_ch <= 'a' + max_alphabet - 1; new_ch++)
        {
            int possible = true; //cout << "i = " << i << " " << new_ch << endl;
            for(int j = i - 1; j >= max(i - 2, 0); j--)
            {
                if(new_ch == S[j])
                    possible = false;
            }

            if(possible)
            { //cout << "i = " << i << endl;
                first_greater_position = i;
                replacement = new_ch;
                break;
            }
        }
    } //cout << replacement << " " << first_greater_position << endl;

    if(first_greater_position == NOT_FOUND)
    {
        cout << "NO\n";
        return 0;
    }

    string next_good_string;
    for(int i = 0 ; i < first_greater_position; i++)
        next_good_string += S[i];

    next_good_string += replacement;

    for(int i = first_greater_position + 1; i < length; i++)
    {
        char current_char;

        for(current_char = 'a'; current_char <= 'c'; current_char++)
        {
            if( (i - 1 >= 0 && next_good_string[i - 1] != current_char) &&
                (i - 2 >= 0 && next_good_string[i - 2] != current_char) )
            {
                break;
            }
        }

        next_good_string += current_char;
    }

    cout << next_good_string;
    return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<int,int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

bool palindromic(string &s, int l) {
	for (size_t i = size_t(max(0, l - 2)); i + 1 < s.length(); ++i) {
		if (s[i] == s[i + 1]) return true;
		if (i + 2 < s.length() && s[i] == s[i + 2]) return true;
	}
	return false;
}

bool increase(string &s, int p, int &back) {
	int i = s.size() - 1;
	while (i >= 0) {
		s[i]++;
		if (s[i] - 'a' >= p) s[i] = 'a';
		else break;
		--i;
	}
	back = i;
	return i >= 0;
}

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

	int n, p;
	cin >> n >> p;

	string s;
	cin >> s;

	// Increase the string 'by one'
	bool next = false;
	int back;
	while (!next) {
		if (!increase(s, p, back)) break;
		if (!palindromic(s, back)) next = true;
	}

	if (next)	cout << s << endl;
	else		cout << "NO" << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<int,int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

bool lowest(string &s, int pos, int p, char &val) {
	char v = s[pos];
	if (v - 'a' >= p) return false;
	while (v - 'a' < p) {
		if (pos > 0 && s[pos-1] == v) ++v;
		else if (pos > 1 && s[pos-2] == v) ++v;
		else break;
	}
	if (v - 'a' >= p) return false;
	val = v;
	return true;
}

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

	int n, p;
	cin >> n >> p;

	string s;
	cin >> s;

	int i = n - 1;
	while (i >= 0) {
		char c;
		++s[i];
		if (lowest(s, i, p, c)) {
			s[i] = c;
			break;
		} else {
			s[i] = 'a';
			--i;
		}
	}

	if (i < 0) cout << "NO" << endl;
	else {
		bool y = true;
		char c;
		for (i = i + 1; i < n; ++i) {
			y = y && lowest(s, i, p, c);
			s[i] = c;
		}
		if (!y) cout << "NO" << endl;
		else cout << s << endl;
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<int,int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

bool palindromic(string &s, int l) {
	for (size_t i = size_t(max(0, l - 4)); i + 1 < s.length(); ++i) {
		if (s[i] == s[i + 1]) return true;
		if (i + 2 < s.length() && s[i] == s[i + 2]) return true;
	}
	return false;
}

bool increase(string &s, int p, int &back) {
	int i = s.size() - 1;
	while (i >= 0) {
		s[i]++;
		if (s[i] - 'a' >= p) s[i] = 'a';
		else break;
		--i;
	}
	back = i;
	return i >= 0;
}

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

	int n, p;
	cin >> n >> p;

	string s;
	cin >> s;

	// Increase the string 'by one'
	bool next = false;
	int back = 0;
	while (!next) {
		if (!increase(s, p, back)) break;
		if (!palindromic(s, back)) next = true;
	}

	if (next)	cout << s << endl;
	else		cout << "NO" << endl;

	return 0;
}


#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <iterator>
#include <algorithm>
#include <cmath>
#include <chrono>
#include <cassert>

using namespace std;
using ll = long long;
using ld = long double;
using ii = pair<int,int>;
using vi = vector<int>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vii = vector<ii>;
using vvii = vector<vii>;

const int INF = 2000000000;
const ll LLINF = 9000000000000000000;

bool palindromic(string &s) {
	for (size_t i = 0; i + 1 < s.length(); ++i) {
		if (s[i] == s[i + 1]) return true;
		if (i + 2 < s.length() && s[i] == s[i + 2]) return true;
	}
	return false;
}

bool increase(string &s, int p) {
	int i = s.size() - 1;
	while (i >= 0) {
		s[i]++;
		if (s[i] - 'a' >= p) s[i] = 'a';
		else break;
		--i;
	}
	return i >= 0;
}

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

	int n, p;
	cin >> n >> p;

	string s;
	cin >> s;

	// Increase the string 'by one'
	bool next = false;
	while (!next) {
		if (!increase(s, p)) break;
		if (!palindromic(s)) next = true;
	}

	if (next)	cout << s << endl;
	else		cout << "NO" << endl;

	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
using namespace std;

int main() {
	LL n,m,add=1;
	string s;
	cin>>n>>m>>s;
	for(int i=s.size()-1;i>=0;i--){
		if(add) s[i]++;
		if(s[i]-96>m) add = 1,s[i]='a';
		else add = 0;
	}
	if(add){
		cout<<"NO"<<endl;
		return 0;
	}
	while(true){
		bool check=true,reset=false;
		for(int i=1;i<s.size();i++){
			if(i>1){
				while(s[i]==s[i-1] || s[i]==s[i-2]){
					add = 1;
					check=false;
					reset=true;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}
			else{
				while(s[i]==s[i-1]){
					add = 1;
					check=false;
					reset=true;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}
			if(reset){
				for(int j=i+1;j<s.size();j++) s[j]='a';
			}
		}
		if(check) break;
	}
	cout<<s<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
using namespace std;

int main() {
	LL n,m,add=1;
	string s;
	cin>>n>>m>>s;
	for(int i=s.size()-1;i>=0;i--){
		if(add) s[i]++;
		if(s[i]-96>m) add = 1,s[i]='a';
		else add = 0;
	}
	if(add){
		cout<<"NO"<<endl;
		return 0;
	}
	while(true){
		bool check=true;
		for(int i=1;i<s.size();i++){
			if(i>1){
				while(s[i]==s[i-1] || s[i]==s[i-2]){
					add = 1;
					check=false;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}
			else{
				while(s[i]==s[i-1]){
					add = 1;
					check=false;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}
		}
		if(check) break;
	}
	cout<<s<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
using namespace std;

int main() {
	LL n,m,add=1;
	string s;
	cin>>n>>m>>s;
	for(int i=s.size()-1;i>=0;i--){
		if(add) s[i]++;
		if(s[i]-96>m) add = 1,s[i]='a';
		else add = 0;
	}
	if(add){
		cout<<"NO"<<endl;
		return 0;
	}
	while(true){
		bool check=true;
		for(int i=1;i<s.size();i++){
			if(i>1){
				while(s[i]==s[i-1] || s[i]==s[i-2]){
					add = 1;
					check=false;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}
			else{
				while(s[i]==s[i-1]){
					add = 1;
					check=false;
					for(int j=i;j>=0;j--){
						if(add) s[j]++;
						if(s[j]-96>m) add = 1,s[j]='a';
						else add = 0;
					}
					if(add){
						cout<<"NO"<<endl;
						return 0;
					}
				}
			}cout<<s<<endl;
		}
		if(check) break;
	}
	cout<<s<<endl;
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
int a[1002],i,j,n,m,k,l,o,p;
char s[1003];
bool flag;
void dfs(int x)
{
	int i;if (flag) return;
	if (x>n) return;
	flag=false;
	for (i=1;i<=m;i++)
    if (i!=a[x-1]&&i!=a[x-2])
    if (!flag)
    {
    	flag=true;
    	a[x]=i;
    	dfs(x+1);
	}
}
int main()
{
	scanf("%d%d\n",&n,&m);
	scanf("%s",s);
	for (i=0;i<n;i++)
	 a[i+1]=s[i]-96;
	l=n+1;
	while (l>1)
	{
		l--;
		for (i=a[l]+1;i<=m;i++)
		 if (i!=a[l-1]&&i!=a[l-2])
		 {
		 flag=true;
		 a[l]=i;break;
	     }
	     if (flag) break;
	}
	if (!flag)
	{
	printf("NO");
	return 0;
    }
    if (l<n)
    {
    flag=false;
    dfs(l+1);
    	if (!flag)
	{
	printf("NO");
	return 0;
    }
    }
    for (i=1;i<=n;i++)
    printf("%c",a[i]+96);
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <cstdlib>

using namespace std;

int a[1005];
char cc[1005];
int n,k;
void nn()
{
	for (int i=n;i>=1;i--)
	{
		a[i]++;
		if (a[i]<=k) break;
		a[i]=1;
	 }
}
int flag;
bool judge()
{
	int i;
	flag = 1;
	for (i=n;i>=2;i--)
	{
		if (a[i]!=9) flag = 0;
		if (a[i]==a[i-1]) return 0;
		if (i>=3)
		if (a[i]==a[i-2]) return 0;
	}
	if (a[1]!=9) flag = 0;
	if (flag) return 1;
		for (int i=1;i<=n;i++)
	{
		char c = 'a'-1+a[i];
		printf("%c",c);
	 }
	return 1;
}
int main(void)
{
//	freopen("aaa.in","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",cc);
	for (int i=1;i<=n;i++)
		a[i] = (int)(cc[i-1]-'a')+1;
//	for (int i=1;i<=n;i++)
//	printf("%d",a[i]);
	nn();
	while (!judge())
	{
		nn();
	}
	if (flag)
	cout<<"NO"<<endl;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n,p,b[1001],nb,cnt,pos;
char s[1001];
bool check(int x){
	//puts(s);
		if(x-1>=0&&s[x]==s[x-1]) return 0;
		if(x-2>=0&&s[x]==s[x-2]) return 0;
		if(x-2>=0&&x-1>=0&&s[x-1]==s[x-2]) return 0;
	return 1;
}
bool c2(){
	int cc=0;
	for(int x=0;x<n;++x){
		if(s[x]>='a'+p-1) ++cc;
	}
	if(cc==n) return 0;
	return 1;
}

int main(){
	scanf("%d%d%s",&n,&p,s);
	nb=n;
	if(n==1&&s[0]<'a'+p-1){
		s[0]++;
		puts(s);
		return 0;
	}
	if(c2()==0){
			puts("NO");
			return 0;
		}
	pos=n-1;
	while(1){
		if(pos<0){
			puts("NO");
			return 0;
		}
		if(pos>=n){
			puts(s);
			return 0;
		}
		if(s[pos]=='a'+p-1){
			s[pos]='a'-1;
			--pos;
			continue;
		}
		++s[pos];
		if(check(pos)){
			++pos;
		}
	}
	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstdlib>

using namespace std;

int n,p;
char cc[1010];
int a[1010];
bool flag = false;
void dfs(int ios)
{
//	cout<<ios<<endl;
	if (ios==n+1)
	{
		flag = true;
		return ;
	}
	for (int i=1;i<=p;i++)
	{
			if (ios>=2)
		if (i==a[ios-1]) continue;
		if (ios>=3)
		if (i==a[ios-2]) continue;
		a[ios] = i;
		dfs(ios+1);
		if (flag) break;
	}
	return ;
 }
int main(void)
{
//	freopen("aaa.in","r",stdin);
	scanf("%d%d",&n,&p);
	scanf("%s",cc);
	for (int i=1;i<=n;i++)
	a[i] = cc[i-1]-'a'+1;
	for (int i=n;i>=1;i--)
	{
	for (int j=a[i]+1;j<=p;j++)
	{
		if (i>=2)
		if (j==a[i-1]) continue;
		if (i>=3)
		if (j==a[i-2]) continue;
		a[i] = j;
		dfs(i+1);
		if (flag) break;
	}
	if (flag) break;
	}
	if (flag)
	{
		for (int i=1;i<=n;i++)
		{
		char c = a[i]-1+'a';
		printf("%c",c);
		}
	}
	else
	{
		printf("NO");
	}
	return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <list>
const int maxn =2000;
#define pb push_back
using namespace std;
const int mod = 1e9+7;
int n,k,x,z,p;
char s[maxn];
int f[maxn];
bool check(){
    for(int i=1;i<n;i++){
        if(s[i]==s[i+1]) return false;
    }
    for(int i=2;i<=n-1;i++){
        if(s[i+1]==s[i-1]) return false;
    }
    return 1;
}
int main(){
    cin >> n >> p;
    cin >> (s+1);
    while(1){
        int v = 0;
        int chong = 0;
        if(s[n]<p+'a'-1){
            s[n]++;
        }
        else{
            s[n] = 'a';
            int j = n-1;
            while(j>=1){
                if(s[j]=='a'+p-1){
                    s[j] = 'a';
                    j--;
                }
                else{
                    s[j]++;
                    chong = 1;
                    v = 1;
                    break;
                }
            }
            if(!v){
                cout<<"NO";return 0;
            }

        } if(check()){
            cout<<(s+1);
            return 0;
        }
    }

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int N = 1005;

struct State
{
	int len, x, y, id;

	State() {}
	State(int a, int b, int c, int d) : len(a), x(b), y(c), id(d) {}
};

State from[N][30][30][2];

bool vis[N][30][30][2];

char s[N];

int n, p;

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n >> p >> (s + 1);
	queue<State> q;
	q.push(State(0, 26, 26, 0));
	State ed(-1, -1, -1, -1);
	while (!q.empty())
	{
		State cur = q.front();
		q.pop();
		if (cur.len == n && cur.id == 1)
		{
			ed = cur;
			break;
		}
		if (cur.len == n)
			continue;
		int c = (cur.id > 0 ? 0 : s[cur.len + 1] - 'a');
		for (int i = c; i < p; i++)
		{
			if (i != cur.x && i != cur.y && !vis[cur.len + 1][cur.y][i][cur.id | (i > c)])
			{
				vis[cur.len + 1][cur.y][i][cur.id | (i > c)] = 1;
				from[cur.len + 1][cur.y][i][cur.id | (i > c)] = cur;
				q.push(State(cur.len + 1, cur.y, i, cur.id | (i > c)));
			}
		}
	}
	if (ed.len == -1)
	{
		cout << "NO" << endl;
		exit(0);
	}
	vector<char> res;
	while (ed.len > 0)
	{
		res.push_back('a' + ed.y);
		int a = ed.len, b = ed.x, c = ed.y, d = ed.id;
		ed = from[a][b][c][d];
	}
	reverse(res.begin(), res.end());
	for (auto c : res)
		cout << c;
	cout << endl;
	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstdlib>

using namespace std;

int n,p;
char cc[1010];
int a[1010];
bool flag = false;
void dfs(int ios)
{
//	cout<<ios<<endl;
	if (ios==n+1)
	{
		flag = true;
		return ;
	}
	for (int i=1;i<=p;i++)
	{
			if (ios>=2)
		if (i==a[ios-1]) continue;
		if (ios>=3)
		if (i==a[ios-2]) continue;
		a[ios] = i;
		dfs(ios+1);
		if (flag) break;
	}
	return ;
 }
int main(void)
{
//	freopen("aaa.in","r",stdin);
	scanf("%d%d",&n,&p);
	scanf("%s",cc);
	for (int i=1;i<=n;i++)
	a[i] = cc[i-1]-'a'+1;
	for (int i=n;i>=1;i--)
	{
	for (int j=a[i]+1;j<=p;j++)
	{
		if (i>=2)
		if (j==a[i-1]) continue;
		if (i>=3)
		if (j==a[i-2]) continue;
		a[i] = j;
		dfs(i+1);
		if (flag) break;
	}
	if (flag) break;
	}
	if (flag)
	{
		for (int i=1;i<=n;i++)
		{
		char c = a[i]-1+'a';
		printf("%c",c);
		}
	}
	else
	{
		printf("No");
	}
	return 0;
}


# include <iostream>
# include <cstdio>
# include <cstring>
# include <cstdlib>

using namespace std;

int a[1005];
int flag;
char cc[1005];
int n,k;
void nn()
{
	for (int i=n;i>=1;i--)
	{

//		if (i>=3)
//		while (a[i]==aa[i]==a[i-1]) a[i]++;

		a[i]++;
		while (a[i]==a[i+1]) i++;
		while (a[i]==a[i-1]) a[i]++;
		if (a[i]<=k) return;
		a[i]=1;
	 }
	 flag = 1;
}

bool judge()
{
	if (flag==1) return 1;
	int i;
	for (i=n;i>=2;i--)
	{
		if (a[i]==a[i-1]) return 0;
		if (i>=3)
		if (a[i]==a[i-2]) return 0;
	}
		for (int i=1;i<=n;i++)
	{
		char c = 'a'-1+a[i];
		printf("%c",c);
	 }
	return 1;
}
int main(void)
{
//	freopen("aaa.in","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",cc);
	for (int i=1;i<=n;i++)
		a[i] = (int)(cc[i-1]-'a')+1;
//	for (int i=1;i<=n;i++)
//	printf("%d",a[i]);
	nn();
	while (!judge())
	{
//		for (int i=1;i<=n;i++)
//	{
//		char c = 'a'-1+a[i];
//		printf("%c",c);
//	 }
//	 cout<<endl;
		nn();
	}
	if (flag)
	cout<<"NO"<<endl;
	return 0;
}


#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iostream>
#include <vector>
#include <list>
const int maxn =2000;
#define pb push_back
using namespace std;
const int mod = 1e9+7;
int n,k,x,z,p;
char s[maxn];
int f[maxn];
int check(){
    for(int i=n;i>=2;i--){
        if(s[i]==s[i-1]) return i;
    }
    for(int i=n-1;i>=2;i--){
        if(s[i+1]==s[i-1]) return i+1;
    }
    return 0;
}
int main(){
    cin >> n >> p;
    cin >> (s+1);
    int ss = 0;
    int loc = n;
    while(1){
        if(s[loc]<p+'a'-1){
            s[loc]++;
        }
        else{
            s[loc] = 'a';
            int j = loc-1;
            while(j>=1){
                if(s[j]=='a'+p-1){
                    s[j] = 'a';
                    j--;
                }
                else{
                    s[j]++;
                    break;
                }
            }
            if(j==0){
                cout<<"NO";return 0;
            }
        }
        loc = check();
        if(loc ==0){
            cout<<(s+1);
            return 0;
        }
    }

    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<stdio.h>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
using namespace std;
const int maxn=1100;
int n,m;
char s[maxn],ans[maxn];
int main()
{
	scanf("%d%d",&n,&m);
	scanf("%s",s+1);
	int len=strlen(s+1);
	bool fff=0;
	for(int i=s[len-2]-'a';i<m;++i)
	{
		ans[len-2]='a'+i;
		for(int j=0;j<m;++j)
		{
			if(i==j)continue;
			if(i==s[len-2]-'a'&&j<s[len-1]-'a')continue;
			ans[len-1]='a'+j;
			for(int k=0;k<m;++k)
			{
				if(k==j||k==i)continue;
				if(i==s[len-2]-'a'&&j==s[len-1]-'a'&&k<=s[len]-'a')continue;
				ans[len]='a'+k;
				fff=1;
				break;
			}
			if(fff)break;
		}
		if(fff)break;
	}
	//	for(int i=0;i<=len;++i)printf("%c",ans[i]);
	if(!fff)
	{
		printf("NO\n");
		return 0;
	}
	for(int i=len-3;i;--i)
	{
		for(char j=s[i];j<='z';++j)
		{
			if(j==ans[i+1]||j==ans[i+2])continue;
			ans[i]=j;
			break;
		}
	}
	for(int i=1;i<=len;++i)printf("%c",ans[i]);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
int a[1202],i,j,n,m,k,l,o,p;
char s[1203];
bool flag;
void dfs(int x)
{
	int i;if (flag) return;
	if (x>n)
	{
	flag=true;
	return;
    }
	for (i=1;i<=m;i++)
    if (i!=a[x-1]&&i!=a[x-2])
    if (!flag)
    {
    	a[x]=i;
    	dfs(x+1);
	}
}
int main()
{
	scanf("%d%d\n",&n,&m);
	scanf("%s",s);
	for (i=0;i<n;i++)
	 a[i+1]=s[i]-96;
	l=n+1;
	while (l>1)
	{
		l--;
		for (i=a[l]+1;i<=m;i++)
		 if (l==1||(i!=a[l-1]&&i!=a[l-2]))
		 {
		 flag=true;
		 a[l]=i;break;
	     }
	     if (flag) break;
	}
	if (!flag)
	{
	printf("NO");
	return 0;
    }
    if (l<n)
    {
    flag=false;
    dfs(l+1);
    	if (!flag)
	{
	printf("NO");
	return 0;
    }
    }
    for (i=1;i<=n;i++)
    printf("%c",a[i]+96);
}


#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N = 1e5 + 5;

string next(string s, int p) {
    string t;
    t = s;
    t[s.size() - 1] = s[s.size() - 1] + 1;
    if(t[s.size() - 1] == 'a' + p) t[s.size() - 1] = 'a';
    for(int i = s.size() - 2; i >= 0; i--) {
        if(t[i + 1] == 'a' && s[i + 1] == 'a' + p - 1) {
            t[i]++;
            if(t[i] == 'a' + p) t[i] = 'a';
        }
    }
    if(t[0] == 'a' && s[0] == 'a' + p - 1) t = "1";
    return t;
}

bool check(string s) {
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == s[i + 1] || s[i] == s[i + 2]) return 0;
    }
    return 1;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    while(1) {
        string t = next(s, p);
        s = t;
        if(t == "1") break;
        if(check(t)) return cout << t, 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N = 1e5 + 5;

string next(string s, int p) {
    string t;
    t = s;
    t[s.size() - 1] = s[s.size() - 1] + 1;
    if(t[s.size() - 1] == 'a' + p) t[s.size() - 1] = 'a';
    for(int i = s.size() - 2; i >= 0; i--) {
        if(t[i + 1] == 'a' && s[i + 1] == 'a' + p - 1) {
            t[i]++;
            if(t[i] == 'a' + p) t[i] = 'a';
        }
    }
    if(t[0] == 'a' && s[0] == 'a' + p - 1) t = "1";
    return t;
}

bool check(string s) {
    for(int i = 0; i < s.size(); i++) {
        if(s[i] == s[i + 1] || s[i] == s[i + 2]) return 0;
    }
    return 1;
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, p;
    cin >> n >> p;
    string s;
    cin >> s;
    ll k = 0;
    while(k < 50) {
        k++;
        string t = next(s, p);
        s = t;
        //cout << t << "\n";
        if(t == "1") break;
        if(check(t)) return cout << t, 0;
    }
    cout << "NO";
}


#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int N = 1e5 + 5;
ll a[N];

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int n, p;
    string s;
    cin >> n >> p >>  s;
    int i = n - 1;
    while(i >= 0) {
        s[i]++;
        if(s[i] == 'a' + p) {
            i--;
            continue;
        }
        if(s[i] != s[i - 1] && s[i] != s[i - 2]) break;
    }
    if(i == -1) return cout << "NO", 0;
    for(int j = 0; j <= i; j++)
        cout << s[j];
    for(int j = i + 1; j < n; j++) {
        char k = 'a';
        while(k == s[j - 1] || k == s[j - 2]) k++;
        s[j] = k;
        cout << k;
    }

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"}, aux3[] = {"cab"};
	int k = 0;
	string a, b, c;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( ( s[i-1] == a && s[i-2] == b ) || ( s[i-1] == b && s[i-2] == 'a' ) ) return resp + c;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		c += aux3[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"};
	int k = 0;
	string a, b;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux[(k+1)%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"}, aux3[] = {"cab"} aux4[] = {"acb"}, aux5[] = {"bca"}, aux6[] = {"cba"};
	int k = 0;
	string a, b, C, d, e;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( c == 'b' && s[i-1] == 'a' ) return resp + C;
			if( s[i-1] == 'b' && c == 'a' ) return resp + f;
			if( c == 'a' ) return resp + e;
			if( c == 'b' ) return resp + d;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		C += aux3[k%3];
		d += aux4[k%3];
		e += aux5[k%3];
		f += aux6[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"};
	int k = 0;
	string a, b;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux[(k+1)%3];
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"}, aux3[] = {"cab"};
	int k = 0;
	string a, b, C;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( ( s[i-1] == 'a' && c == 'b' ) || ( s[i-1] == 'b' && c == 'a' ) ) return resp + C;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		C += aux3[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"};
	int k = 0;
	string a, b;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"}, aux3[] = {"cab"}, aux4[] = {"acb"}, aux5[] = {"bca"}, aux6[] = {"cba"};
	int k = 0;
	string a, b, C, d, e, f;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( c == 'b' && s[i-1] == 'a' ) return resp + C;
			if( s[i-1] == 'b' && c == 'a' ) return resp + f;
			if( c == 'a' ) return resp + e;
			if( c == 'b' ) return resp + d;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		C += aux3[k%3];
		d += aux4[k%3];
		e += aux5[k%3];
		f += aux6[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>

#define INF 0x3F3F3F3F
#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define pb push_back
#define pi 3.1415926535897932384626433832795028841971
#define debug(x) cout << #x << " = " << x << endl;
#define debug2(x,y) cout << #x << " = " << x << " --- " << #y << " " << y << "\n";
#define debugM( x, l, c ) { rep( i, 0, l ){ rep( j, 0, c ) printf("%d ", x[i][j]); printf("\n");}}
#define all(S) (S).begin(), (S).end()
#define MAXV 1010000
#define MAXN 110
#define F first
#define S second
#define EPS 1e-9
#define mk make_pair

using namespace std;

typedef pair <int, int> ii;
typedef long long int ll;

int n, m;
string s;
char M;

string solve(){
	char aux[] = {"abc"}, aux2[] = {"bac"}, aux3[] = {"cab"};
	int k = 0;
	string a, b, c;
	for( int i = s.size()-1; i > 1; i-- ){
		for( char c = s[i]+1; c < M; c++ ){
			if( s[i-1] == c || s[i-2] == c ) continue;
			string resp = s.substr( 2, i-2 );
			resp += c;
			if( ( s[i-1] == 'a' && s[i-2] == 'b' ) || ( s[i-1] == 'b' && s[i-2] == 'a' ) ) return resp + c;
			if( s[i-1] != 'a' ) return resp + a;
			else return resp + b;
		}
		a += aux[k%3];
		b += aux2[k%3];
		c += aux3[k%3];
		k++;
	}
	return "";
}

int main(){

	while( scanf("%d%d", &n, &m ) != EOF ){
		cin >> s;
		s = "$$" + s;
		M = char( 'a' + m );
		string s = solve();
		if( s.empty() || m == 1 || ( m == 2 && n > 2 ) ) puts("NO");
		else printf("%s\n", s.c_str() );
	}

}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair <int,int> pii;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
	int n,p;
	cin >> n >> p;
	string s; //zir reshteye palin be toole 2 ya 3 nadare
	cin >> s;
	bool found = 0;
	int pos;
	for (int i = n - 1 ; i >= 0 ; i--)
	{
		for (int j = s[i] + 1 ; j <= 'a' + p - 1 ; j++)
		{
			char cur = j;
			if (cur != s[i - 1] && cur != s[i - 2])
			{
				s[i] = cur;
				pos = i;
				found = 1;
				break;
			}
		}
		if (found)
			break;
	}
	if (!found)
		return cout << "NO" << endl , 0;

	for (int i = pos + 1 ; i < s.size() ; i++)
	{
		for (char cur = 'a' ; cur <= 'a' + p - 1 ; cur++)
			if (cur != s[i - 1] && cur != s[i - 2])
			{
				s[i] = cur;
				break;
			}
	}
	cout << s << endl;
 	return 0;
}


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

long long a,b;

long long getc3(long long c)
{
    long long l=1,r=c;
    while(l<r)
    {
        long long mid = (l+r)/2;
        if((mid*mid*mid)>=c)
            r=mid;
        else
            l=mid+1;
    }
}

int main()
{
    int t;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&a,&b);
        long long c = a* b;
        long long d = getc3(c);
        if(d*d*d!=c) {printf("NO\n");continue;}
        if(a%d!=0 || b%d!=0) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


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

long long a,b;
int lena,lenb;
struct node
{
    long long n;
    int sum;
}da[15],db[15];
void init()
{
    memset(da,0,sizeof(da));
    memset(db,0,sizeof(db));
    lena = lenb =0;
    long long n =2; int temp = 0;
    while(n<=a)
    {
        if(a%n==0) { temp++; a /= n; }
        else {
            if(temp>0) { da[lena].n = n; da[lena++].sum=temp; }
//cout << lena << " 1 " << da[lena-1].sum << endl;
            n++,temp=0;
        }
    }
//cout<<temp<<endl;
    if(temp>0) { da[lena].n = n; da[lena++].sum=temp; }
//cout<<lena<<" 2 "<<da[lena-1].sum<<endl;
    n =2,temp = 0;
    while(n<=b)
    {
        if(b%n==0){ temp++; b /= n; }
        else{
            if(temp>0) { db[lenb].n = n; db[lenb++].sum=temp;  }
            n++,temp=0;
        }
    }
    if(temp>0) { db[lenb].n = n; db[lenb++].sum=temp; }
}
int main()
{
    int t;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&a,&b);
        if(a<b)swap(a,b);
        init();
//cout<<"lena = "<<lena<<endl;
//for(int i=0;i<lena;i++)
//    printf("n=%I64d %d %d\n",da[i].n,da[i].sum,db[i].sum);
        if(lenb!=lena) {printf("NO\n"); continue;}
        int i=0;
        for(;i<lena;i++)
        {
            if(da[i].n!=db[i].n) break;
            int nowa=da[i].sum,nowb=db[i].sum;
            if(nowa<nowb) swap(nowa,nowb);
            if(nowa>2*nowb) break;
            nowa = 2*nowb-nowa;
            if(nowa%3!=0) break;
        }
        if(i<lena) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


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

long long a,b;

long long getc3(long long c)
{
    long long l=1,r=1e6+10;
    while(l<r)
    {
        long long mid = (l+r)/2;
        if((mid*mid*mid)>=c)
            r=mid;
        else
            l=mid+1;
    }
    return r;
}

int main()
{
    int t;

    scanf("%d",&t);
    while(t--)
    {
        scanf("%I64d%I64d",&a,&b);
        if(a==b)
        {
            if(a%3==0) printf("YES\n");
            else printf("NO\n");
            continue;
        }
        long long c = a* b;
//cout<<c<<endl;
        long long d = getc3(c);
//cout<<d<<endl;
        if(d*d*d!=c) {printf("NO\n");continue;}
        if(a%d!=0 || b%d!=0) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


#include <iostream>

using namespace std;

int gcd (long long a, long long b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

long long R(long long k) {
    long long n = 1000000000, kol = 0;
    for (long long i = 2; i <= n && k!=1; i++) {
        while (k % i==0) {
            kol++;
            k/=i;
        }
    }

    return kol;
}

int main() {
    long long n, i, l, r, g, l1, r1;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        if (l==1 && r==1) {
            cout << "YES" << endl;
        } else {
            g = gcd(l, r);
            l1 = l/g;
            r1 = r/g;
            //cout << l1 << ' ' << r1 << ' ' << g << endl;
            if (l1*r1==g) {
                cout << "YES" << endl;
            } else {
                if (l1==1 && r1==1 && g!=1) {
                    int kol = R(g);
                    if (kol==0 || kol%3==0) {
                        cout << "YES" << endl;
                    } else {
                        cout << "NO" << endl;
                    }
                } else if (r1==1 && g!=1) {
                    if (g % r1!=0) {
                        cout << "NO" << endl;
                    } else {
                        int kol = R(g), kol1 = R(r1);
                        if ((kol-kol1)%2==0) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else if (l1==1 && g!=1) {
                    if (g % l1!=0) {
                        cout << "NO" << endl;
                    } else {
                        int kol = R(g), kol1 = R(l1);
                        if ((kol-kol1)%2==0) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else  {
                    cout << "NO" << endl;
                }
            }
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) != l*r) {
            cout << "NO" << endl;
            continue;
        } else {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) != l*r) {
            cout << "NO" << endl;
            continue;
        } else {
            g++;
        }
        if (g*g*g != l*r) {
            cout << "NO" << endl;
            continue;
        } else if (l % g == 0 && r % g == 0 && ) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) != l*r) {
            cout << "NO" << endl;
            continue;
        } else {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) != l*r) {
            cout << "NO" << endl;
            continue;
        } else {
            g++;
        }
        if (g*g*g != l*r) {
            cout << "NO" << endl;
            continue;
        } else if (l % g == 0 && r % g == 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>
#include <stdlib.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    scanf("%I64d", &n);

    for (i = 0; i < n; i++) {
        scanf("%I64d%I64d", &l, &r);
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) == l*r) {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) == l*r) {
            g++;
        }
        if (g*g*g != l*r) {
            printf("NO");
        } else if (l % g == 0 && r % g == 0) {
            printf("YES");
        } else {
            printf("NO");
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        g = (long long)pow(l*r, 1/3.0);
        cout << g << endl;
        if ((g-1)*(g-1)*(g-1)==l*r) {
            cout << "YES" << endl;
        } else if ((g+1)*(g+1)*(g+1)==l*r) {
            cout << "YES" << endl;
        } else if (g*g*g!=l*r) {
            cout << "NO" << endl;
        } else if (l % g==0 && r % g == 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) == l*r) {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) == l*r) {
            g++;
        }
        if (g*g*g != l*r) {
            cout << "NO" << endl;
        } else if (l % g == 0 && r % g == 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1)==l*r) {
            cout << "YES" << endl;
        } else if ((g+1)*(g+1)*(g+1)==l*r) {
            cout << "YES" << endl;
        } else if (g*g*g!=l*r) {
            cout << "NO" << endl;
        } else if (l % g==0 && r % g == 0) {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }
    }

    return 0;
}


#include <iostream>

using namespace std;

int gcd (long long a, long long b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

long long R(long long k) {
    long long n = 1000000000, kol = 0;
    for (long long i = 2; i <= n && k!=1; i++) {
        while (k % i==0) {
            kol++;
            k/=i;
        }
    }

    return kol;
}

int main() {
    long long n, i, l, r, g, l1, r1;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        if (l==1 && r==1) {
            cout << "YES" << endl;
        } else {
            g = gcd(l, r);
            l1 = l/g;
            r1 = r/g;
            //cout << l1 << ' ' << r1 << ' ' << g << endl;
            if (l1*r1==g) {
                cout << "YES" << endl;
            } else {
                if (l1==1 && r1==1 && g!=1) {
                    int kol = R(g);
                    if (kol==0 || kol%3==0) {
                        cout << "YES" << endl;
                    } else {
                        cout << "NO" << endl;
                    }
                } else if (r1==1 && g!=1) {
                    if (g % r1!=0) {
                        cout << "NO" << endl;
                    } else {
                        int kol = R(g), kol1 = R(r1);
                        if ((kol-kol1)%2==0) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else if (l1==1 && g!=1) {
                    if (g % l1!=0) {
                        cout << "NO" << endl;
                    } else {
                        int kol = R(g), kol1 = R(l1);
                        if ((kol-kol1)%2==0) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else  {
                    int kol = R(g), kol1 = R(l1), kol2 = R(r1);
                    if ((kol-kol1-kol2)%2==0) {
                        cout << "YES" << endl;
                    } else {
                        cout << "NO" << endl;
                    }
                }
            }
        }
    }

    return 0;
}


#include <iostream>
#include <math.h>

using namespace std;

int main() {
    long long n, i, l, r, g;

    scanf("%I64d", &n);

    for (i = 0; i < n; i++) {
        scanf("%I64d%I64d", &l, &r);
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) == l*r) {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) == l*r) {
            g++;
        }
        if (g*g*g != l*r) {
            printf("NO");
        } else if (l % g == 0 && r % g == 0) {
            printf("YES");
        } else {
            printf("NO");
        }
    }

    return 0;
}


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

using namespace std;

int main() {
    long long n, i, l, r, g;

    scanf("%I64d", &n);

    for (i = 0; i < n; i++) {
        scanf("%I64d%I64d", &l, &r);
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) == l*r) {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) == l*r) {
            g++;
        }
        if (g*g*g != l*r) {
            printf("NO");
        } else if (l % g == 0 && r % g == 0) {
            printf("YES");
        } else {
            printf("NO");
        }
    }

    return 0;
}


#include <iostream>

using namespace std;

int gcd (long long a, long long b) {
	if (b == 0)
		return a;
	else
		return gcd (b, a % b);
}

bool R(long long k) {
    long long n = 1000000000, kol = 0;
    for (long long i = 2; i <= n && k!=1; i++) {
        while (k % i==0) {
            kol++;
            k/=i;
        }
    }

    if (kol==0 || kol%3==0) {
        return true;
    }
    return false;
}

int main() {
    long long n, i, l, r, g, l1, r1;

    cin >> n;

    for (i = 0; i < n; i++) {
        cin >> l >> r;
        if (l==1 && r==1) {
            cout << "YES" << endl;
        } else {
            g = gcd(l, r);
            l1 = l/g;
            r1 = r/g;
            //cout << l1 << ' ' << r1 << ' ' << g << endl;
            if (l1*r1==g) {
                cout << "YES" << endl;
            } else {
                if (l1==1 && r1==1 && g!=1) {
                    if (R(g)) {
                        cout << "YES" << endl;
                    } else {
                        cout << "NO" << endl;
                    }
                } else if (r1==1 && g!=1) {
                    if (g % r1!=0) {
                        cout << "NO" << endl;
                    } else {
                        g/=r1;
                        if (R(g)) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else if (l1==1 && g!=1) {
                    if (g % l1!=0) {
                        cout << "NO" << endl;
                    } else {
                        g/=l1;
                        if (R(g)) {
                            cout << "YES" << endl;
                        } else {
                            cout << "NO" << endl;
                        }
                    }
                } else  {
                    cout << "NO" << endl;
                }
            }
        }
    }

    return 0;
}


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

using namespace std;

int main() {
    long long n, i, l, r, g;

    scanf("%I64d", &n);

    for (i = 0; i < n; i++) {
        scanf("%I64d%I64d", &l, &r);
        g = (long long)pow(l*r, 1/3.0);
        //cout << g << endl;
        if ((g-1)*(g-1)*(g-1) == l*r) {
            g--;
        }
        if ((g+1)*(g+1)*(g+1) == l*r) {
            g++;
        }
        if (g*g*g != l*r) {
            printf("NO\n");
        } else if (l % g == 0 && r % g == 0) {
            printf("YES\n");
        } else {
            printf("NO\n");
        }
    }

    return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long

int zdgy(int a, int b)
{
	return b == 0 ? a : zdgy(b, a % b);
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		LL a, b, c, d;
		cin >> a >> b;
		c = a * b;
		d = pow(1.0 * c, 1.0 / 3);
		//cout << f << endl;
		bool bj = 0;
		for(LL j = d - 1; j <= d + 1; j++)
			if(j * j * j == c)
			{
				bj = 1;
				break;
			}
		if(!bj)
		{
			cout << "No" << endl;
			continue ;
		}
		cout << "Yes" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
#define MAXN 200000+1109

using namespace std;

int n,K,q;
long long a,b;

int main()
{
	int T;
	long long x,y;
	double s;
	for(scanf("%d",&T);T;T--)
	{
		scanf("%I64d%I64d",&a,&b);
		x=a*b;
		s=pow((double)x,1.0/3.0);
		y=s;
		if((y)*(y)*(y)==x&&a%(y)==0&&b%(y)==0) printf("Yes\n");
		else if((y+1)*(y+1)*(y+1)==x&&a%(y+1)==0&&b%(y+1)==0) printf("Yes\n");
		else if((y-1)*(y-1)*(y-1)==x&&a%(y-1)==0&&b%(y-1)==0) printf("Yes\n");
		else printf("No\n");
	}

	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long

int zdgy(int a, int b)
{
	return b == 0 ? a : zdgy(b, a % b);
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		int a, b, c, d, e, f;
		cin >> a >> b;
		c = zdgy(a, b);
		d = a / c * b / c;
		if(c % d != 0)
		{
			cout << "No" << endl;
			continue ;
		}
		e = c / d;
		f = pow(1.0 * e, 1.0 / 3);
		//cout << f << endl;
		bool bj = 0;
		for(int j = f - 5; j <= f + 5; j++)
			if(j * j * j == e)
			{
				bj = 1;
				break;
			}
		if(!bj)
		{
			cout << "No" << endl;
			continue ;
		}
		cout << "Yes" << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long

int zdgy(int a, int b)
{
	return b == 0 ? a : zdgy(b, a % b);
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		LL a, b, c, d;
		cin >> a >> b;
		c = a * b;
		d = pow(1.0 * c, 1.0 / 3);
		//cout << f << endl;
		bool bj = 0;
		for(LL j = d - 1; j <= d + 1; j++)
			if(j * j * j == c)
			{
				d = j;
				bj = 1;
				break;
			}
		if(!bj)
		{
			cout << "No" << endl;
			continue ;
		}
		if(a % d != 0 || b % d != 0)
		{
			cout << "No" << endl;
			continue ;
		}
		cout << "Yes" << endl;
	}
	return 0;
}


#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long

int zdgy(int a, int b)
{
	return b == 0 ? a : zdgy(b, a % b);
}

int main()
{
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		LL a, b, c, d;
		cin >> a >> b;
		c = a * b;
		d = round(pow(1.0 * c, 1.0 / 3));
		//cout << f << endl;
		if(d * d * d != c)
		{
			cout << "No" << endl;
			continue ;
		}
		if(a % d != 0 || b % d != 0)
		{
			cout << "No" << endl;
			continue ;
		}
		cout << "Yes" << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000000;
long long vis[maxn + 10000];
int main()
{
    for (long long i = 1; i <= maxn; i++)
        vis[i] = i * i * i;
    int n;
    scanf("%d", &n);
    while (n--)
    {
        long long a, b;
        cin >> a >> b;
        if (a == 1 && b == 1)
        {
            puts("Yes");
            continue;
        }
        long long c = a * b;
        int k = lower_bound(vis, vis + maxn, c) - vis;
        if (c == vis[k])
        {
            if (a % k == 0 && b % k == 0)
                puts("Yes");
            else
                puts("No");
        }
        else
            puts("No");
    }
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 500000;
long long vis[maxn + 10000];
int main()
{
    for (long long i = 1; i <= maxn; i++)
        vis[i] = i * i * i;
    int n;
    scanf("%d", &n);
    while (n--)
    {
        long long a, b;
        cin >> a >> b;
        if (a == 1 && b == 1)
        {
            puts("Yes");
            continue;
        }
        long long c = a * b;
        int k = lower_bound(vis, vis + maxn, c) - vis;
        if (c == vis[k])
        {
            if (a % k == 0 && b % k == 0)
                puts("Yes");
            else
                puts("No");
        }
        else
            puts("No");
    }
}


#include <cstdio>
using namespace std;
int main()
{
    long long a,b,n,l,r,mid,t,sum;
    scanf("%lld",&n);
    while(n--)
    {
        scanf("%lld %lld",&a,&b);
        l=1;
        r=1000000;
        sum=a*b;
        while(l<=r)
        {
            mid=(l+r)/2;
            t=mid*mid*mid;
            if(t>sum)
            {
                r=mid-1;
            }
            else if(t<sum)
            {
                l=mid+1;
            }
            else
            {
                break;
            }
        }
        if(l<=r&&a%mid==0&&b%mid==0)
        {
            printf("Yes\n");
        }
        else
        {
            printf("No\n");
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define maxn 100055
ll a[maxn];
int main()
{
    ll n, m, c, d;
    int i;
    while(~scanf("%lld %lld %lld %lld", &n, &m, &c, &d))//雇员个数, 客户个数, 雇员进来时间间隔, 门打开持续时间
    {
        for(i = 0; i < m; i++)
        {
            scanf("%lld", &a[i]);
        }
        sort(a, a + m);//客户进来的时间
        ll ans = 0;
        ll tt = d / c;//开一次门可以进 tt + 1个雇员
        ll t1 = 1, t2, last = 0;
        ll k, num, r;
        for(i = 0; i < m;)
        {
            if(t1 <= n)  //还有雇员没进来
            {
                t2 = a[i]/c;//到a[i]这个时刻，进来了多少个雇员
                if(t2 > n) t2 = n;
                k = t2 - t1 + 1;//上一个时刻到这一个时刻，进来了多少个雇员
                if(k > 0)
                {
                    ans += k/(tt+1);//需要开几次门
                    if(k%(tt+1) != 0) ans++;//还有余的雇员没进，需要多开一次门
                    num = k%(tt+1);
                    if(num == 0) num = tt+1;
                    r = t2 - num + 1;//求出开的最后一次门 是那个雇员第一个进
                    last = r*c + d;//门持续到的时刻
                    t1 = last/c + 1;//更新当前进了多少个雇员
                }
            }
            if(last < a[i])//如果门持续时间，没能让客户进，打开门次数+1
            {
                ans++;
                last = a[i] + d;//更新门持续时间
                t1 = last / c + 1;//更新当前进了多少个雇员
            }
            while(last >= a[i])
            {
                i++;
            }
        }
        if(n >= t1)//客户进完了，还剩下雇员的情况
        {
            ans += (n-t1+1) / (tt+1);
            if((n-t1+1)%(tt+1) != 0) ans++;
        }
        printf("%lld\n", ans);
    }
    return 0;
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
int sushu[20000],SN=1;
bool fenjie(int a,int*arr){
    for(int i=0;i<SN&&a>=sushu[i];i++){
        while(a%sushu[i]==0){
            a/=sushu[i];
            arr[i]++;
        }
    }
    if(a==1)return true;
    return false;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int ans[50][50];
    for(int i=0;i<50;i++)
        for(int j=0;j<50;j++)
            ans[i][j]=0;
    ans[0][0]=1;
    queue<int>q;
    q.push(0);
    q.push(0);
    while(!q.empty()){
        int x=q.front(),y;
        q.pop();
        y=q.front();
        q.pop();
   //     cout<<"("<<x<<","<<y<<")  \n";
        if(x>32||y>32)continue;
        if(ans[x+1][y+2]==0){
            ans[x+1][y+2]=1;
            q.push(x+1);
            q.push(y+2);
        }
        if(ans[x+2][y+1]==0){
            ans[x+2][y+1]=1;
            q.push(x+2);
            q.push(y+1);
        }
    }
    sushu[0]=2;
    for(int i=3;i<40000;i+=2){
        int flag=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag){
            sushu[SN]=i;
            SN++;
        }
    }

  /*
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<SN;i++)
        cout<<sushu[i]<<" ";// */
    int n;
    cin>>n;
    int a1[20000],a2[20000];
    while(n--){
        int a,b;
        scanf("%d%d",&a,&b);
        for(int i=0;i<20000;i++)
            a1[i]=a2[i]=0;
        int flag=1;
        if(!fenjie(a,a1))flag=0;
        if(flag&&!fenjie(b,a2))flag=0;
        for(int i=0;flag&&i<20000;i++){
            if(ans[a1[i]][a2[i]]==0){
                flag=0;
                break;
            }
        }
        if(flag)printf("yes\n");
        else printf("no\n");
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
int sushu[20000],SN=1;
bool fenjie(int a,int*arr){
    for(int i=0;i<SN&&a>=sushu[i];i++){
        while(a%sushu[i]==0){
            a/=sushu[i];
            arr[i]++;
        }
    }
    if(a==1)return true;
    return false;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int ans[50][50];
    for(int i=0;i<50;i++)
        for(int j=0;j<50;j++)
            ans[i][j]=0;
    ans[0][0]=1;
    queue<int>q;
    q.push(0);
    q.push(0);
    while(!q.empty()){
        int x=q.front(),y;
        q.pop();
        y=q.front();
        q.pop();
   //     cout<<"("<<x<<","<<y<<")  \n";
        if(x>32||y>32)continue;
        if(ans[x+1][y+2]==0){
            ans[x+1][y+2]=1;
            q.push(x+1);
            q.push(y+2);
        }
        if(ans[x+2][y+1]==0){
            ans[x+2][y+1]=1;
            q.push(x+2);
            q.push(y+1);
        }
    }
    sushu[0]=2;
    for(int i=3;i<40000;i+=2){
        int flag=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag){
            sushu[SN]=i;
            SN++;
        }
    }

  /*
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<SN;i++)
        cout<<sushu[i]<<" ";// */
    int n;
    cin>>n;
    int a1[20000],a2[20000];
    while(n--){
        int a,b;
        cin>>a>>b;
        for(int i=0;i<20000;i++)
            a1[i]=a2[i]=0;
        int flag=1;
        if(!fenjie(a,a1))flag=0;
        if(!fenjie(b,a2))flag=0;
        for(int i=0;i<20000;i++){
            if(ans[a1[i]][a2[i]]==0){
                flag=0;
                break;
            }
        }
        if(flag)cout<<"yes\n";
        else cout<<"no\n";
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
ll cubic_root(ll x){
    ll l=0,r=1000005;
    while(l<r){
        ll m=(l+r)/2;
        ll f=m*m*m;
        if(f>x)r=m-1;
        else if(f==x)return m;
        else l=m+1;
    }
    return l;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int n;
    cin>>n;
    while(n--){
        ll a,b;
        scanf("%ld %ld",&a,&b);
        ll x=cubic_root(a*b);
        if(x*x*x!=a*b)
            cout<<"NO\n";
        else if(a%x==0&&b%x==0)
            cout<<"YES\n";
        else
            cout<<"no\n";
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
int sushu[20000],SN=1;
void fenjie(int a,int*arr){
    for(int i=0;i<SN&&a>=sushu[i];i++){
        while(a%sushu[i]==0){
            a/=sushu[i];
            arr[i]++;
        }
    }
}
int main(){
    int ans[50][50];
    for(int i=0;i<50;i++)
        for(int j=0;j<50;j++)
            ans[i][j]=0;
    ans[0][0]=1;
    queue<int>q;
    q.push(0);
    q.push(0);
    while(!q.empty()){
        int x=q.front(),y;
        q.pop();
        y=q.front();
        q.pop();
   //     cout<<"("<<x<<","<<y<<")  \n";
        if(x>32||y>32)continue;
        if(ans[x+1][y+2]==0){
            ans[x+1][y+2]=1;
            q.push(x+1);
            q.push(y+2);
        }
        if(ans[x+2][y+1]==0){
            ans[x+2][y+1]=1;
            q.push(x+2);
            q.push(y+1);
        }
    }
    sushu[0]=2;
    for(int i=3;i<40000;i+=2){
        int flag=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag){
            sushu[SN]=i;
            SN++;
        }
    }

  /*  for(int i=0;i<50;i++){
        for(int j=0;j<50;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<SN;i++)
        cout<<sushu[i]<<" ";*/
    int n;
    cin>>n;
    int a1[20000],a2[20000];
    while(n--){
        int a,b;
        cin>>a>>b;
        for(int i=0;i<20000;i++)
            a1[i]=a2[i]=0;
        fenjie(a,a1);
        fenjie(b,a2);
        int flag=1;
        for(int i=0;i<20000;i++){
            if(ans[a1[i]][a2[i]]==0){
                flag=0;
                break;
            }
        }
        if(flag)cout<<"yes\n";
        else cout<<"no\n";
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
ll cubic_root(ll x){
    ll l=0,r=1000005;
    while(l<r){
        ll m=(l+r)/2;
        ll f=m*m*m;
        if(f>x)r=m-1;
        else if(f==x)return m;
        else l=m+1;
    }
    return l;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int n;
    cin>>n;
    while(n--){
        ll a,b;
        scanf("%I64d %I64d",&a,&b);
        ll x=cubic_root(a*b);
        if(x*x*x!=a*b)
            cout<<"NO\n";
        else if(a%x==0&&b%x==0)
            cout<<"YES\n";
        else
            cout<<"no\n";
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
int sushu[20000],SN=1;
bool fenjie(int a,int*arr){
    for(int i=0;i<SN&&a>=sushu[i];i++){
        while(a%sushu[i]==0){
            a/=sushu[i];
            arr[i]++;
        }
    }
    if(a==1)return true;
    return false;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int ans[50][50];
    for(int i=0;i<50;i++)
        for(int j=0;j<50;j++)
            ans[i][j]=0;
    ans[0][0]=1;
    queue<int>q;
    q.push(0);
    q.push(0);
    while(!q.empty()){
        int x=q.front(),y;
        q.pop();
        y=q.front();
        q.pop();
   //     cout<<"("<<x<<","<<y<<")  \n";
        if(x>32||y>32)continue;
        if(ans[x+1][y+2]==0){
            ans[x+1][y+2]=1;
            q.push(x+1);
            q.push(y+2);
        }
        if(ans[x+2][y+1]==0){
            ans[x+2][y+1]=1;
            q.push(x+2);
            q.push(y+1);
        }
    }
    sushu[0]=2;
    for(int i=3;i<40000;i+=2){
        int flag=1;
        for(int j=2;j*j<=i;j++){
            if(i%j==0){
                flag=0;
                break;
            }
        }
        if(flag){
            sushu[SN]=i;
            SN++;
        }
    }

  /*
    for(int i=0;i<50;i++){
        for(int j=0;j<50;j++)
            cout<<ans[i][j]<<" ";
        cout<<endl;
    }
    cout<<endl;
    for(int i=0;i<SN;i++)
        cout<<sushu[i]<<" ";// */
    int n;
    cin>>n;
    int a1[20000],a2[20000];
    while(n--){
        int a,b;
        scanf("%d%d",&a,&b);
        for(int i=0;i<20000;i++)
            a1[i]=a2[i]=0;
        int flag=1;
        if(!fenjie(a,a1))flag=0;
        if(!fenjie(b,a2))flag=0;
        for(int i=0;i<20000;i++){
            if(ans[a1[i]][a2[i]]==0){
                flag=0;
                break;
            }
        }
        if(flag)printf("yes\n");
        else printf("no\n");
    }
}


#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
typedef long long ll;
ll cubic_root(ll x){
    ll l=0,r=1000005;
    while(l<r){
        ll m=(l+r)/2;
        ll f=m*m*m;
        if(f>x)r=m-1;
        else if(f==x)return m;
        else l=m+1;
    }
    return l;
}
int main(){
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
#endif
    int n;
    cin>>n;
    while(n--){
        ll a,b;
        cin>>a>>b;
        ll x=cubic_root(a*b);
        if(x*x*x!=a*b)
            cout<<"NO\n";
        else if(a%x==0&&b%x==0)
            cout<<"YES\n";
        else
            cout<<"no\n";
    }
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	f[1]=false;
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	cout<<prime[top]<<endl;
	//cout<<top<<endl;
	//for (i=1;i<=top;i++) cout<<prime[i]<<endl;
	LL fst,snd;
	LL cnt1,cnt2,ss;
	while (n--)
	{
		cin>>x>>y;
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		//cout<<mid<<endl;
		int k=1;bool superf=true;
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			bool pp=true;
			if (f[mid])
			{
				LL cnt1=0,cnt2=0,ss;
				if (pp) ss=prime[k];
				else
				{
					ss=mid;
					mid=1;
				}
				while (x%ss==0)
				{
					x/=ss;
					cnt1++;
				}
				while (y%ss==0)
				{
					y/=ss;
					cnt2++;
				}
				if (cnt1>cnt2) swap(cnt1,cnt2);
				if (cnt2-cnt1>cnt1)
				{
					superf=false;
					break;
				}
				break;
			}
			while (mid%prime[k]!=0)
			{
				k++;
			}
			while (mid%prime[k]==0) mid/=prime[k];
			cnt1=0;cnt2=0;
			ss=prime[k];
			while (x%ss==0)
			{
				x/=ss;
				cnt1++;
			}
			while (y%ss==0)
			{
				y/=ss;
				cnt2++;
			}
			if (cnt1>cnt2) swap(cnt1,cnt2);
			if (cnt2-cnt1>cnt1)
			{
				superf=false;
				break;
			}
				/*fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;*/
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	LL fst,snd;
	while (n--)
	{
		cin>>x>>y;
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		//cout<<mid<<endl;
		int k=1;bool superf=true;
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			while (mid%prime[k]!=0) k++;
			while (mid%prime[k]==0) mid/=prime[k];
			LL cnt1=0,cnt2=0;
			while (x%prime[k]==0)
			{
				x/=prime[k];
				cnt1++;
			}
			while (y%prime[k]==0)
			{
				y/=prime[k];
				cnt2++;
			}
			if (cnt1>cnt2) swap(cnt1,cnt2);
			if (cnt2-cnt1>cnt1)
			{
				superf=false;
				break;
			}
				/*fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;*/
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	LL fst,snd;
	while (n--)
	{
		cin>>x>>y;
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		int k=1;bool superf=true;
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			while (mid%prime[k]!=0) k++;
			while (mid%prime[k]==0)
			{

				mid/=prime[k];
				fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;
			}
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	LL first,second;
	while (n--)
	{
		scanf("%I64d%I64d",&x,&y);
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		int k=1;bool superf=true;
		while (mid!=1)
		{
			while (mid%prime[k]!=0) k++;
			while (mid%prime[k]==0)
			{
				mid/=prime[k];
				first=prime[k];second=prime[k]*prime[k];
				if (x%first==0 && y%second==0)
				{
					x/=first;y/=second;
					continue;
				}
				if (x%second==0 && y%first==0)
				{
					x/=second;y/=first;
					continue;
				}
				superf=false;
				break;
			}
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

LL gcd(LL a,LL b)
{
	return b==0?a:gcd(b,a%b);
}

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	f[1]=false;
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	//cout<<prime[top]<<endl;
	//cout<<top<<endl;
	//for (i=1;i<=top;i++) cout<<prime[i]<<endl;
	LL fst,snd;
	LL cnt1,cnt2,ss;
	while (n--)
	{
		scanf("%I64d%I64d",&x,&y);
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		//cout<<mid<<endl;
		int k=1;bool superf=true;
		LL g=gcd(x,y);
		mid=min(mid,g);
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			if (f[mid])
			{
				LL cnt1=0,cnt2=0,ss;
				ss=mid;
				while (x%ss==0)
				{
					x/=ss;
					cnt1++;
				}
				while (y%ss==0)
				{
					y/=ss;
					cnt2++;
				}
				if (cnt1>cnt2) swap(cnt1,cnt2);
				if (cnt2-cnt1>cnt1)
				{
					superf=false;
					break;
				}
				break;
			}
			while (mid%prime[k]!=0)
			{
				k++;
			}
			while (mid%prime[k]==0) mid/=prime[k];
			cnt1=0;cnt2=0;
			ss=prime[k];
			while (x%ss==0)
			{
				x/=ss;
				cnt1++;
			}
			while (y%ss==0)
			{
				y/=ss;
				cnt2++;
			}
			if (cnt1>cnt2) swap(cnt1,cnt2);
			if (cnt2-cnt1>cnt1)
			{
				superf=false;
				break;
			}
				/*fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;*/
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	f[1]=false;
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	//cout<<prime[top]<<endl;
	//cout<<top<<endl;
	//for (i=1;i<=top;i++) cout<<prime[i]<<endl;
	LL fst,snd;
	LL cnt1,cnt2,ss;
	while (n--)
	{
		cin>>x>>y;
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		//cout<<mid<<endl;
		int k=1;bool superf=true;
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			bool pp=true;
			if (f[mid])
			{
				LL cnt1=0,cnt2=0,ss;
				ss=mid;
				while (x%ss==0)
				{
					x/=ss;
					cnt1++;
				}
				while (y%ss==0)
				{
					y/=ss;
					cnt2++;
				}
				if (cnt1>cnt2) swap(cnt1,cnt2);
				if (cnt2-cnt1>cnt1)
				{
					superf=false;
					break;
				}
				break;
			}
			while (mid%prime[k]!=0)
			{
				k++;
			}
			while (mid%prime[k]==0) mid/=prime[k];
			cnt1=0;cnt2=0;
			ss=prime[k];
			while (x%ss==0)
			{
				x/=ss;
				cnt1++;
			}
			while (y%ss==0)
			{
				y/=ss;
				cnt2++;
			}
			if (cnt1>cnt2) swap(cnt1,cnt2);
			if (cnt2-cnt1>cnt1)
			{
				superf=false;
				break;
			}
				/*fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;*/
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const int INF=0x7ffffff;
const int magic=348;

int n;
LL x,y,p;
bool f[1000048];
LL prime[1000048],top=0;

LL gcd(LL a,LL b)
{
	return b==0?a:gcd(b,a%b);
}

int main ()
{
	scanf("%d",&n);
	int i,j;
	memset(f,true,sizeof(f));
	f[1]=false;
	for (i=2;i<=1000000;i++)
		if (f[i])
		{
			prime[++top]=i;
			for (j=i*2;j<=1000000;j+=i)
				f[j]=false;
		}
	//cout<<prime[top]<<endl;
	//cout<<top<<endl;
	//for (i=1;i<=top;i++) cout<<prime[i]<<endl;
	LL fst,snd;
	LL cnt1,cnt2,ss;
	while (n--)
	{
		scanf("%I64d%I64d",&x,&y);
		p=x*y;
		bool t=false;
		LL l=1,r=1000000,mid;
		while (l<=r)
		{
			mid=(l+r)>>1;
			if (mid*mid*mid==p)
			{
				t=true;
				break;
			}
			if (mid*mid*mid<p) l=mid+1; else r=mid-1;
		}
		if (!t)
		{
			printf("No\n");
			continue;
		}
		//cout<<mid<<endl;
		int k=1;bool superf=true;
		//LL g=gcd(x,y);
		//mid=min(mid,g);
		//cout<<mid<<endl;
		//cout<<x<<' '<<y<<endl;
		while (mid!=1)
		{
			if (f[mid])
			{
				LL cnt1=0,cnt2=0,ss;
				ss=mid;
				while (x%ss==0)
				{
					x/=ss;
					cnt1++;
				}
				while (y%ss==0)
				{
					y/=ss;
					cnt2++;
				}
				if (cnt1>cnt2) swap(cnt1,cnt2);
				if (cnt2-cnt1>cnt1)
				{
					superf=false;
					break;
				}
				break;
			}
			while (mid%prime[k]!=0)
			{
				k++;
			}
			while (mid%prime[k]==0) mid/=prime[k];
			cnt1=0;cnt2=0;
			ss=prime[k];
			while (x%ss==0)
			{
				x/=ss;
				cnt1++;
			}
			while (y%ss==0)
			{
				y/=ss;
				cnt2++;
			}
			if (cnt1>cnt2) swap(cnt1,cnt2);
			if (cnt2-cnt1>cnt1)
			{
				superf=false;
				break;
			}
				/*fst=prime[k];snd=prime[k]*prime[k];//cout<<x<<' '<<y<<endl;
				//cout<<fst<<' '<<snd<<endl;
				//cout<<x<<' '<<y<<endl;
				if (x%fst==0 && y%snd==0)
				{
					x/=fst;y/=snd;
					continue;
				}
				if (x%snd==0 && y%fst==0)
				{
					x/=snd;y/=fst;
					continue;
				}
				superf=false;
				//cout<<superf<<endl;
				break;*/
			if (!superf) break;
		}
		if (superf) printf("Yes\n"); else printf("No\n");
	}
	return 0;
}