#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <queue> #include <string> #include <string.h> #include <map> #include <vector> typedef long long LL ; int isOk(char c){ return '0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' ; } std::string nextSuccessor(std::string word){ int rightMost ; for(rightMost = word.size()-1 ; rightMost >= 0 ; rightMost--){ if(isOk(word[rightMost])) break ; } if(rightMost >= 0){ if(('0'<= word[rightMost] && word[rightMost] < '9') || ('a' <= word[rightMost] && word[rightMost] < 'z') || ('A' <= word[rightMost] && word[rightMost] < 'Z') ) word[rightMost]++ ; else if(word[rightMost] == '9'){ word[rightMost] = '0' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "1" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } else if(word[rightMost] == 'z'){ word[rightMost] = 'a' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "a" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } else if(word[rightMost] == 'Z'){ word[rightMost] = 'A' ; int fd = 0 ; for(int j = rightMost - 1 ; j >= 0 ; j--){ if(isOk(word[j])) fd = 1 ; } if(! fd){ std::string head = word.substr(0 , rightMost) ; std::string tail = word.substr(rightMost) ; return head + "A" + tail ; } else{ std::string tail = word.substr(rightMost) ; std::string head = word.substr(0 , rightMost) ; return nextSuccessor(head) + tail ; } } } else word[word.size()-1]++ ; return word ; } char word[108] ; int main(){ int t , k ; scanf("%d" , &t) ; while(t--){ scanf("%s%d" ,word , &k) ; std::string s = std::string(word) ; for(int i = 1 ; i <= k ; i++){ s = nextSuccessor(s) ; printf("%s\n" , s.c_str()) ; } puts("") ; } return 0; }