// Lance Bae
// Bergen County Academies
// Intermediate Division

#include 
#include 
#include 
#include 
using namespace std;

string first_half(string N1, int X){
  for(int i = 0; i < N1.size(); i++){
    int curr = N1[i] - '0';
    N1[i] = ((curr + X) % 10) + '0';
  }
  return N1;
}

string second_half(string N2, int X){
  for(int i = 0; i < N2.size(); i++){
    int curr = N2[i] - '0';
    N2[i] = abs(curr - X) + '0';
  }
  return N2;
}

void change(string N, int P, int counter){
  int X = N[N.size() - P] - '0';
  string N1 = N.substr(0, N.size() - P); string N2 = N.substr(N.size() - P + 1, N.size() - 1);
  string result1 = first_half(N1, X); string result2 = second_half(N2, X);
  cout << counter << ". " << result1 << X << result2 << '\n';
}


int main(){
  ifstream fin ("int-sample-input.txt");
  for(int i = 1; i < 6; i++){
    string N; int P;
    fin >> N >> P;
    change(N, P, i);
  }
}