#include 
#include 
using namespace std;


int main() {
  string num;
  int n, number = 0;
  for(int i = 0; i < 5; i ++){
  cin >> num >> n;
  for(int i = 0; i < num.length() - n; i ++){
    number = num[i] + num[num.length() - n] - 96;
    if(number >= 10){
      num[i] = (number % 10) + 48;
    }
    else{
      num[i] = number + 48;
    }
  }
  for(int i = num.length() - n + 1; i < num.length(); i ++){
    number = abs(num[i] - num[num.length() - n]);
    if(number < 0){
      number = -1 * number;
    }
    num[i] = number + 48;
  }
  cout << num << endl;
  }
}