#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define inarr(a,n) for(int i=0;i<n;i++) cin>>a[i]
#define outarr(a,n) for(int i=0;i<n;i++) cout<<a[i]<<" "; cout<<endl
#define maxa(a,n) *max_element(a,a+n)
#define mina(a,n) *min_element(a,a+n)
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define fr(i,s,e) for(ll i=s;i<e;i++)
#define rf(i,s,e) for(ll i=s-1;i>=e;i--)
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define sz size()
#define all(v) v.begin(),v.end()
typedef int ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<long long,long long> > vpll;
#define PI 3.141592653589793
#define MOD 1000000007
bool flag=0,flag1=0,flag2=0;
ll d,x,y;
ll p=7919,b=11,len; // len - overall length of inut string
void Eu(ll a,ll v)
{
if(v==0)
{
d=a;
x=1;
y=0;
}
else
{
Eu(v,a%v);
ll temp=x;
x=y;
y=temp-(a/v)*y;
}
}
ll Eux(ll a,ll m)
{
Eu(a%m,m);
return (x%m+m)%m;
}
string encode(int p,int b,string a)
{
fr(i,0,len)
a[i]=(char)((int)((p*(int)a[i]+b)+31)%158);
return a;
}
string decode(int p,int b,string c)
{
ll inverse=Eux(p,158);
fr(i,0,len)
c[i]=(char)(((((((int)c[i]+127)%127-b)*inverse)-31)%127));
return c;
}
int main()
{
IOS
int p,b;
cin>>p>>b;
string a,e,c; getline(cin,a);
len=a.length(); // input string- a , encoded string- b , decoded string- c
e=encode(p,b,a);
c=decode(p,b,e);
cout<<e<<endl;
cout<<c<<endl;
// cout<<(p*(int)'a'+b)<<endl;
// cout<<(char)((((p*(int)''+b)%127-b)*Eux(p,127))%127);
}
I2luY2x1ZGUgPGJpdHMvc3RkY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