;(function () {
	var n = readline().split(' ');
	var k = +n[1];
	n = +n[0];

	var s = readline().split(' ');
	var x = 0;
	for (var i = 0; i < s.length; i++) {
		x += s[i].split('').filter(function (e) { return /[47]/.test(e); }).length <= k;
	}

	print(x);

}).call(this);

const readline = require('readline');
const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout,
  terminal: false
});
let c = 0;

rl.on('line', (d) => {
  if (c === 0) {
    c++;
    [n, k] = d.split(' ').map(Number);
    return;
  }

  const arr = d.split(' ');
  let ans = 0;

  for (let i = 0; i < arr.length; i++) {
    let counter = 0;
    for (let j = 0; j < arr[i].length; j++) {
      if (arr[i][j] === '4' || arr[i][j] === '7') {
        counter++;
      }
    }

    if (counter <= k) {
      ans++;
    }
  }

  console.log(ans);

  c++;
});

function main(stdin) {
    var lines = stdin.split("\n");
    var _a = lines[0].split(" ").map(function (v) { return parseInt(v); }), n = _a[0], k = _a[1];
    var count = 0;
    lines[1].split(" ").forEach(function (v) {
        var amount = Array.from(v).reduce(function (acc, cur) { return (["4", "7"].includes(cur) ? acc + 1 : acc); }, 0);
        if (amount <= k)
            count++;
    });
    console.log(count);
}
main(require("fs").readFileSync(0, "utf-8"));

print(function(n,k){
	return readline().split(' ').filter(function(s){
		return s.replace(/[^47]+/g, '').length<=k;
	}).length;
}.apply(0, readline().split(' ').map(Number)))

var info = readline().split(' ').map(Number);
var Arr = readline().split(' ');
var result = 0;
for (i=0; i<info[0]; i++) {
    var chP = 0;
    if (Arr[i].length <= info[1]) {
                result += 1;
    }
    else {
        for (var j=0; j<Arr[i].length; j++) {
            if (Arr[i].charAt(j) == "4" || Arr[i].charAt(j) == "7") {
                chP += 1;
            }
        }
        if (chP <= info[1]) {
                result += 1;
        }
    }
}
print(result);

var tokens = [];
var numTokens = 0;
function next(){
	while(numTokens >= tokens.length){
		tokens = readline().split(/[\s]+/);
		numTokens = 0;
	}
	return tokens[numTokens++];
}
function nextInt(){
	return parseInt(next(),10);
}
function main(){
	var n,k,a,i,cont;
	n = nextInt();
	k = nextInt();
	var ans = 0;
	for(i = 0; i < n; i++){
		a = next();
		cont = 0;
		a.split("").forEach(function(c){
			if(c=="4" || c=="7")
				cont++;
		});
		if(cont <= k)
			ans++;
	}
	print(ans);
}
main();


var s = readline(),
	k = parseInt( readline() );

if (0 !== s.length % k) {
	print( 'NO' );
} else {
	var l = s.length / k,
	    l2 = l / 2,
		ok = true;
	for (var i=0; i<l2; i++) {
		for (var j=0; j<k; j++) {
			ok = ok && s[i+j*l] === s[j*l+l-1-i];
		}
	}

	ok ? print( 'YES' ) : print( 'NO' );
}

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = false;

    this.isPalindrome = function( str ) {
    	var i , j , len ;
    	len = str.length ;
    	for( i = 0 , j = len - 1 ; i < j ; i++ , j-- ) {
    		if( str.charAt( i ) != str.charAt( j ) ) {
    			return false ;
    		}
    	}
    	return true ;
    } ;

    this.solveCase = function() {
        var res , i , j , fl , cn , temp , len , a ;
        res = 0 ;
        len = this.s.length ;
        if( len % this.k != 0 ) {
        	print( 'NO' ) ;
        	return null ;
        }
        a = Math.floor( len / this.k ) ;
        temp = '' ;
        for( i = 0 ; i < len ; i++ ) {
        	temp += this.s.charAt( i ) ;
        	if( temp.length == a ) {
        		if( this.isPalindrome( temp ) == true ) {
	        		res++ ;
	        	}
	        	temp = '' ;
        	}
        }
        if( res == this.k ) {
        	print( 'YES' ) ;
        }
        else {
        	print( 'NO' ) ;
        }
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
        	this.s = irObj.nextString();
            this.k = irObj.nextInt();
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.adjList = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.adjList.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adjList = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adjList.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            inputFilePath = currentDirectory + '\\' + inputFileName ;
        }
        else {
            //on linux
            inputFilePath = currentDirectory + '/' + inputFileName ;
        }
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 ) ;
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array() ;

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString ) ;
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array() ;
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath ;
        res = "";
        sz = this.resultantStringArray.length ;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += '\n' ;
            }
            res += this.resultantStringArray[ i ] ;
        }
        fsObj = require( 'fs' ) ;
        currentDirectory = __dirname ;
        if( currentDirectory.indexOf( 'D:' ) != -1 ) {
            //on windows
            outputFilePath = currentDirectory + '\\' + outputFileName ;
        }
        else {
            //on linux
            outputFilePath = currentDirectory + '/' + outputFileName ;
        }
        fsObj.writeFileSync( outputFilePath , res ) ;
        this.clearPercase() ;
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader() ;
    this.psObj = new ProblemSolver() ;
    this.fohObj = new FileOutputHandler() ;

    this.runCases = function() {
		var testCases , hasMoreTestCases , i ;
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt() ;
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase() ;
                this.psObj.getInput( this.irObj ) ;
                this.psObj.solveCase() ;
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase() ;
                hasMoreTestCases = this.psObj.getInput( this.irObj ) ;
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase() ;
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME ) ;
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && ( __dirname.indexOf( 'D:') != -1 || __dirname.indexOf( '/media/') != -1 ) ) {
                    environmentType = 'local-node-js' ;
                }
                else {
                    environmentType = 'server-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj ;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments ) ;
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME ) ;
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log ;
                }
            }
            catch( ex ) {
                print = console.log ;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino() ;
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines() ;
            this.runCases() ;
        }
    } ;

    this.configureStreamsAndReadInput() ;
}

new CodeExecutioner() ;

function ProblemSolver() {
    this.HAS_TEST_CASES = false;
    this.INPUT_FILE_NAME = "test.in";
    this.OUTPUT_FILE_NAME = "out.txt";
    this.DO_OUTPUT_TO_FILE = false;
    this.CLEAR_ARRAY_PER_CASE = false;

    this.isPalindrome = function( str ) {
    	var i , j , len ;
    	len = str.length ;
    	for( i = 0 , j = len - 1 ; i < j ; i++ , j-- ) {
    		if( str.charAt( i ) != str.charAt( j ) ) {
    			return false ;
    		}
    	}
    	return true ;
    } ;

    this.solveCase = function() {
        var res , i , j , fl , cn , temp , len , a ;
        res = 0 ;
        len = this.s.length ;
        if( len % this.k != 0 ) {
        	print( 'NO' ) ;
        	return null ;
        }
        a = Math.floor( len / this.k ) ;
        temp = '' ;
        for( i = 0 ; i < len ; i++ ) {
        	temp += this.s.charAt( i ) ;
        	if( temp.length == a ) {
        		if( this.isPalindrome( temp ) == true ) {
	        		res++ ;
	        	}
	        	temp = '' ;
        	}
        }
        if( res == this.k ) {
        	print( 'YES' ) ;
        }
        else {
        	print( 'NO' ) ;
        }
    };

    this.init = function() {
        this.lim1 = 100010;
        this.lim2 = 110;
        this.cc = 1;
        this.ind = 1;
        this.n = 0;
        this.cn = 0;
        this.declareAndFillArrays();
    };

    this.getInput = function( irObj ) {
        var hasMoreInput , i;
        hasMoreInput = true;
        try {
        	this.s = irObj.nextString();
            this.k = irObj.nextInt();
        }
        catch( ex ) {
            hasMoreInput = false;
        }
        return hasMoreInput;
    };

    this.clearArraysPerCase = function() {
        var i;
        this.arr = new Array();
        this.adjList = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.arr.push( 0 );
            this.adjList.push( new Array() );
        }
    };

    this.clearPerCase = function() {
        this.cn = 0;
        this.cc++;
        if( this.CLEAR_ARRAY_PER_CASE == true ) {
            this.clearArraysPerCase() ;
        }
    };

    this.declareAndFillArrays = function() {
        var i , j;
        this.srr = new Array();
        this.vis = new Array();
        this.arr = new Array();
        this.brr = new Array();
        this.memo = new Array();
        this.done = new Array();
        this.adjList = new Array();
        for( i = 0 ; i < this.lim1 ; i++ ) {
            this.srr.push( "" );
            this.vis.push( 0 );
            this.arr.push( 0 );
            this.brr.push( 0 );
            this.adjList.push( new Array() );
        }
        for( i = 0 ; i < this.lim2 ; i++ ) {
            this.memo.push( new Array() );
            this.done.push( new Array() );
            for( j = 0 ; j < this.lim2 ; j++ ) {
                this.memo[ i ].push( -1 );
                this.done[ i ].push( 0 );
            }
        }
    };

    this.init();
}

function InputReader() {
    var self = this ;
    this.allLines = new Array();
    this.currrentLineNumber = 0;
    this.currrentCharacterIndex = 0;
    this.callBackFunction = null ;
    this.parentContext = null ;

    this.readAllLines = function() {
        var singleLine;
        while( true ) {
            try {
                singleLine = readline();
                if( singleLine == null ) {
                    break;
                }
            }
            catch( ex ) {
                break;
            }
            this.allLines.push( singleLine );
        }
    };

    this.readAllLinesFromRhino = function() {
        var brObj , line ;
        importPackage( java.io ) ;
        importPackage( java.lang ) ;
        brObj = new BufferedReader( new InputStreamReader( System[ 'in' ] ) ) ;
        this.allLines = [] ;
        while( true ) {
            line = brObj.readLine() ;
            if( line == null ) {
                break;
            }
            this.allLines.push( line ) ;
        }
    };

    this.readSingleLinesFromNodeJsJudgeServer = function( chunk ) {
        self.chunkData += chunk ;
    };

    this.readEndFromNodeJsJudgeServer = function() {
        self.parseRawData( self.chunkData ) ;
        self.parentContext.runCases() ;
    };

    this.readAllLinesFromNodeJsJudgeServer = function( parentContext ) {
        this.parentContext = parentContext ;
        process.stdin.resume() ;
        process.stdin.setEncoding( 'utf8' ) ;
        this.chunkData = '' ;
        process.stdin.on( 'data' , this.readSingleLinesFromNodeJsJudgeServer ) ;
        process.stdin.on( 'end' , this.readEndFromNodeJsJudgeServer ) ;
    };

    this.parseRawData = function( data ) {
        var len , i , currentString;
        len = data.length;
        currentString = "";
        this.allLines = [] ;
        for( i = 0 ; i < len ; i++ ) {
            if( data[ i ] == '\r' ) {
            }
            else if( data[ i ] == '\n' ) {
                this.allLines.push( currentString );
                currentString = "";
            }
            else {
                currentString += data[ i ];
            }
        }
        if( currentString != "" ) {
            this.allLines.push( currentString );
        }
    };

    this.readAllLinesFromFile = function( inputFileName ) {
        var currentDirectory , fsObj , inputFilePath , rawData;
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        inputFilePath = currentDirectory + "\\" + inputFileName;
        rawData = fsObj.readFileSync( inputFilePath , "utf8" );
        this.parseRawData( rawData );
    };

    this.next = function( flag ) {
        var len , i , startIdx , res , endIdx;
        if( flag == 0 ) {
            if( this.currrentCharacterIndex != 0 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            res = "";
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                res += '' + this.allLines[ this.currrentLineNumber ].charAt( i ) ;
            }
            this.currrentLineNumber++;
            this.currrentCharacterIndex = 0;
            return res;
        }
        while( true ) {
            if( this.currrentLineNumber >= this.allLines.length ) {
                throw new Error( "No more tokens available!" );
            }
            startIdx = -1;
            len = this.allLines[ this.currrentLineNumber ].length;
            if( typeof( len ) == 'function' ) {
                len = this.allLines[ this.currrentLineNumber ].length() ;
            }
            for( i = this.currrentCharacterIndex ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) != ' '.charCodeAt( 0 ) ) {
                    startIdx = i;
                    break;
                }
            }
            if( startIdx == -1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
                continue;
            }
            res = "";
            endIdx = len - 1 ;
            for( i = startIdx ; i < len ; i++ ) {
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) == ' '.charCodeAt( 0 ) ) {
                    endIdx = i;
                    break;
                }
                if( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) >= 48 && this.allLines[ this.currrentLineNumber ].charCodeAt( i ) <= 57 ) {
                    res += '' + ( this.allLines[ this.currrentLineNumber ].charCodeAt( i ) - 48 ) ;
                }
                else {
                    res += '' + this.allLines[ this.currrentLineNumber ].charAt( i );
                }
            }
            this.currrentCharacterIndex = endIdx;
            if( endIdx == len - 1 ) {
                this.currrentLineNumber++;
                this.currrentCharacterIndex = 0;
            }
            return res;
        }
    };

    this.nextInt = function() {
        return parseInt( this.next( 1 ) );
    };

    this.nextDouble = function() {
        return parseFloat( this.next( 1 ) );
    };

    this.nextString = function() {
        return this.next( 1 );
    };

    this.nextLine = function() {
        return this.next( 0 );
    };
}

function FileOutputHandler() {
    this.resultantStringArray = new Array();

    this.addNewLine = function( newString ) {
        this.resultantStringArray.push( newString );
    };

    this.clearPercase = function() {
        this.resultantStringArray = new Array();
    };

    this.flushOutOutputToFile = function( outputFileName ) {
        var i , sz , res , currentDirectory , fsObj , outputFilePath;
        res = "";
        sz = this.resultantStringArray.length;
        for( i = 0 ; i < sz ; i++ ) {
            if( i != 0 ) {
                res += "\n";
            }
            res += this.resultantStringArray[ i ];
        }
        fsObj = require( 'fs' );
        currentDirectory = __dirname;
        outputFilePath = currentDirectory + "\\" + outputFileName;
        fsObj.writeFileSync( outputFilePath , res );
        this.clearPercase();
    };
}

function CodeExecutioner() {
    this.irObj = new InputReader();
    this.psObj = new ProblemSolver();
    this.fohObj = new FileOutputHandler();

    this.runCases = function() {
        if( this.psObj.HAS_TEST_CASES == true ) {
            testCases = this.irObj.nextInt();
            for( i = 0 ; i < testCases ; i++ ) {
                this.psObj.clearPerCase();
                this.psObj.getInput( this.irObj );
                this.psObj.solveCase();
            }
        }
        else {
            while( true ) {
                this.psObj.clearPerCase();
                hasMoreTestCases = this.psObj.getInput( this.irObj );
                if( hasMoreTestCases == false ) {
                    break;
                }
                this.psObj.solveCase();
            }
        }
        if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
            this.fohObj.flushOutOutputToFile( this.psObj.OUTPUT_FILE_NAME );
        }
    };

    this.detectEnvironmentType = function() {
        var environmentType = null ;
        try {
            if( importPackage != null ) {
                environmentType = 'rhino' ;
            }
        }
        catch( ex1 ) {
            try {
                //for nodejs local server check
                if( __dirname != null && readline != null && typeof( readline ) != 'function' ) {
                    environmentType = 'local-node-js' ;
                }
            }
            catch( ex2 ) {
                try {
                    if( readline == null || typeof( readline ) != 'function' ) {
                        environmentType = 'server-node-js' ;
                    }
                    else {
                        try {
                            if( Map != null ) {
                                environmentType = 'spider-monkey' ;
                            }
                            else {
                                environmentType = 'javascript-v8' ;
                            }
                        }
                        catch( ex3 ) {
                            environmentType = 'javascript-v8' ;
                        }
                    }
                }
                catch( ex3 ) {
                    environmentType = 'server-node-js' ;
                }
            }
        }
        return environmentType ;
    };

    this.configureStreamsAndReadInput = function() {
        var testCases , i , hasMoreTestCases , isLocal , localContext , isNodeJsJudgeServer , environmentType ;
        isNodeJsJudgeServer = false ;
        environmentType = this.detectEnvironmentType() ;
        if( environmentType == 'local-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            if( this.psObj.DO_OUTPUT_TO_FILE == true ) {
                localContext = this.fohObj;
                print = function() {
                    localContext.addNewLine.apply( localContext , arguments );
                }
            }
            this.irObj.readAllLinesFromFile( this.psObj.INPUT_FILE_NAME );
            this.runCases() ;
        }
        else if( environmentType == 'server-node-js' ) {
            try {
                if( print == null || typeof( print ) != 'function' ) {
                    print = console.log;
                }
            }
            catch( ex ) {
                print = console.log;
            }
            this.irObj.readAllLinesFromNodeJsJudgeServer( this ) ;
        }
        else if( environmentType == 'javascript-v8' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
        else if( environmentType == 'rhino' ) {
            this.irObj.readAllLinesFromRhino();
            this.runCases() ;
        }
        else if( environmentType == 'spider-monkey' ) {
            this.irObj.readAllLines();
            this.runCases() ;
        }
    };

    this.configureStreamsAndReadInput();
}

new CodeExecutioner();

function toi(x){return parseInt(x);}
function isP(x){
    for(var i=0;i<x.length;i++){
	if(x[i]!=x[x.length-i-1]){
	    return false;
	}
    }
    return true;
}
var s=readline();
var k=+readline();
var rem=s.length%k;
if(rem!=0){
    print("NO");
}else{
    var t=(s.length-rem)/k;
    for(var i=0;i<k;i++){
	if(isP(s.substring(i*t,(i+1)*t))==false){
	    print("NO");
	    quit();
	}
    }
    print("YES");
}

var str_r = readline(),
    num_r = parseInt( readline() );

var palindrome = function (str) {
    for(var i=0;i<str.length / 2;i++)
        if(str[str.length-i-1] != str[i])
            return false;
    return true;
}

var solve = function(str, num){
    var ok = true;
    var l = Math.floor(str.length / num);
    if(str.length % num != 0) {
        print ("NO");
        return;
    }
    for(var i=0;i<str.length;i+=l) {
        var sub = str.substr(i,l);
        if(!palindrome(sub))
            ok = false;
    }
    if(ok)
        print("YES");
    else
        print ("NO");
};

solve (str_r,num_r);

"use strict";
// Object.defineProperty(exports, "__esModule", { value: true });
// var lol_io_1 = require("lol-io");
var s = readline();
var k = parseInt(readline());
function checkPalindrome(str, start, end) {
    var i = start;
    var j = end - 1;
    while (i < j) {
        if (str[i++] !== str[j--])
            return false;
    }
    return true;
}
function solve(s, k) {
    var n = s.length;
    if (n < k || n % k !== 0)
        return 'NO';
    var palindromeLength = n / k;
    for (var i = 0; i < n; i += palindromeLength) {
        if (!checkPalindrome(s, i, i + palindromeLength))
            return 'NO';
    }
    return 'YES';
}
print(solve(s, k));
// print(solve('saddastavvat', 2));

"use strict";
// Object.defineProperty(exports, "__esModule", { value: true });
// var lol_io_1 = require("lol-io");
var s = readline();
var k = parseInt(readline());
function checkPalindrome(str, start, end) {
    var i = start;
    var j = end - 1;
    while (i < j) {
        if (str[i++] !== str[j--])
            return false;
    }
    return true;
}
function solve(s, k) {
    var n = s.length;
    var palindromeLength = n / k;
    for (var i = 0; i < n; i += palindromeLength) {
        if (!checkPalindrome(s, i, i + palindromeLength))
            return 'NO';
    }
    return 'YES';
}
print(solve('ss', 2));
print(solve('saddastavvat', 2));

"use strict";
// Object.defineProperty(exports, "__esModule", { value: true });
// var lol_io_1 = require("lol-io");
var s = readline();
var k = parseInt(readline());
function checkPalindrome(str, start, end) {
    var i = start;
    var j = end - 1;
    while (i < j) {
        if (str[i++] !== str[j--])
            return false;
    }
    return true;
}
function solve(s, k) {
    var n = s.length;
    var palindromeLength = n / k;
    for (var i = 0; i < n; i += palindromeLength) {
        if (!checkPalindrome(s, i, i + palindromeLength))
            return 'NO';
    }
    return 'YES';
}
print(solve(s, k));


Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t * 2);
  	var primes = Array.from(sieveOfEratos(1000));
  	primes.sort(function(a,b){
    	return a - b;
    });
    for(var i = 0; i < t; i++){
        var n = nextInt();
      	var list = nextIntArray();
      	var gcds = {};
      	for(var j = 0; j < n; j++){
          for(var k = 0; k < primes.length; k++){
            if(list[j] % primes[k] == 0){
              if(gcds[primes[k]]){
                gcds[primes[k]].add(list[j]);
              }else{
                gcds[primes[k]] = new Set([list[j]]);
              }
              break;
            }
          }
        }
      	//myerr(gcds);
      	var keys = Object.keys(gcds);
      	//myerr(keys);
      	output[i * 2] = keys.length;
      	var index = new Array(keys.length);
      	for(var j = 0; j < keys.length; j++){
          index[j] = keys[j];
        }
      	var thisOut = new Array(n);
      	for(var j = 0; j < n; j++){
          for(var k = 0; k < keys.length; k++){
            if(gcds[keys[k]].has(list[j])){
              thisOut[j] = (k + 1);
              break;
            }
          }
        }
      	output[i * 2 + 1] = myconv(thisOut,8);
    }
    myout(myconv(output,9));
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}
function sieveOfEratos(val){
  var primes = new Set();
  var nums = new Set();
  var used = [2,3,5,7,11];//これらは既に素数であるとする
  var underPrime = 13;//この値から+2ごとに追加。↑の値で割り切れたものは何もしない
  if(val <= 1){
     return nums;
  }
  for(var i = 0; i < used.length; i++){if(used[i] <= val){nums.add(used[i]);}}
  for(var i = underPrime; i <= val; i=i+2){
    var continued = false;
    for(var j = 0; j < used.length; j++){
      if(i % used[j] == 0){continued = true; break;}
    }
    if(continued){continue;}
    nums.add(i);
  }
  for(var i = 2; i <= Math.sqrt(val); (i==2) ? i++ : i=i+2){
    if(!nums.has(i)){continue;}
    var count = 1;
    while(i * count <= val){
      if(i <= 11 && used.indexOf(i) != -1){break;}
      if(count == 1){primes.add(i);}
      nums.delete(i*count);
      count++;
    }
  }
  var primeItr = Array.from(primes);
  for(var i = 0; i < primeItr.length; i++){
    nums.add(primeItr[i]);
  }
  return nums;
}

Main();
function myout(t){print(t);}//standard output
function next(){return readline();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す
//6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
//atcoderのサンプルは最後に改行入れること
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main() {
    var t = nextInt();
    var output = new Array(t * 2);
    output[0] = 2;
    output[1] = "1 1 2";
    output[2] = 2;
    output[3] = "1 2";
    output[4] = 11;
    output[5] = "4 7 8 10 7 3 10 7 7 8 3 1 1 5 5 9 2 2 3 3 4 11 6";
    myout(myconv(output,9));
}


var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// used for look_for parameter
var plus = '+';
var minus = '-';

// if possible get rebus with this function
var getRebus = function(increase, ones, look_for) {
	var sum = 0;
	if (increase == count.plus) {
		sum = ones + n;
	} else {
		sum = ones - n;
	}

	var diff = sum - increase;
	var a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n
	var b = diff % (n - 1) + 1; // b --> change another ? to b
	var counter = 0; // used to count how many ?'s are replaced with n (count a)

	// if diff is 0, I want every ? to be 1
	if (diff === 0) {
		rebus[0] = 1;
	// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)
	} else if (a === 0 && increase == count.plus) {
		rebus[0] = b;
	} else {
		// ONLY when increasing +?'s
		if (increase == count.plus) {
			rebus[0] = n;
			counter = 1;
		// ONLY when increasing -?'s
		} else {
			rebus[0] = 1;
		}
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == look_for) {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == look_for) {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}
	}

	// replacing all other ?'s with 1's
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}

	rebus = rebus.join(' ');

	return rebus;
};

// Increase 'minus' ?'s
if (count.plus - count.minus > n) {
	var sum = count.plus - n;
	if (sum >= count.minus && sum <= count.minus * n) {
		print('Possible');
		print(getRebus(count.minus, count.plus, minus));
	} else {
		print('Impossible');
	}
// Increase 'plus' ?'s
} else {
	var sum = count.minus + n;
	if (sum >= count.plus && sum <= count.plus * n) {
		print('Possible');
		print(getRebus(count.plus, count.minus, plus));
	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (diff === 0) {
			rebus[0] = 1;
		} else if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q > n && n > 1 && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = first_q - n + 1;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (first_q - n + 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (count.minus - count.plus+ 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a <= x; a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && b == 0 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {
		print('Possible');

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus (add +1 to 'plus' because of the very first '?' is + by default)

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// used for look_for parameter
var plus = '+';
var minus = '-';

// if possible get rebus with this function
var getRebus = function(increase, ones, look_for) {
	var sum = 0;
	if (increase == count.plus) {
		sum = ones + n;
	} else {
		sum = ones - n;
	}

	var diff = sum - increase;
	var a = Math.floor(diff / (n - 1)); // a --> change a number of ?'s to n
	var b = diff % (n - 1) + 1; // b --> change another ? to b
	var counter = 0; // used to count how many ?'s are replaced with n (count a)

	// if diff is 0, I want every ? to be 1
	if (diff === 0) {
		rebus[0] = 1;
	// if I want 'n' to appear 0 times, the first ? must be b (ONLY do this when increasing +?'s)
	} else if (a === 0 && increase == count.plus) {
		rebus[0] = b;
	} else if (a >= 1) {
		// ONLY when increasing +?'s
		if (increase == count.plus) {
			rebus[0] = n;
			counter = 1;
		// ONLY when increasing -?'s
		} else {
			rebus[0] = 1;
		}
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace ? with n a times, the next replacement should be b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == look_for) {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == look_for) {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}
	}

	// replacing all other ?'s with 1's
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}

	rebus = rebus.join(' ');

	return rebus;
};

// Increase 'minus' ?'s
if (count.plus - count.minus > n) {
	var sum = count.plus - n;
	if (sum >= count.minus && sum <= count.minus * n) {
		print('Possible');
		print(getRebus(count.minus, count.plus, minus));
	} else {
		print('Impossible');
	}
// Increase 'plus' ?'s
} else {
	var sum = count.minus + n;
	if (sum >= count.plus && sum <= count.plus * n) {
		print('Possible');
		print(getRebus(count.plus, count.minus, plus));
	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

/* x is what we need to add in the rebus instead of a 1
it must be less than n though.... so if it's bigger than n
then we need to divide it into a bunch of n's plus a remaineder
a is the number of n's
b is the remainder */
var x = (first_q - n + 1);

var a = 1;
var b = 0;

// to find 2 unknowns (a and b) we need a double loop..
if (x < n) {
	b = x;
} else {
	for (a = Math.floor(x / n); a < Math.floor(x / n + 2); a++) {
		for (b = 0; b < n; b++) {
			if (a * n + b == x + a) {
				break;
			}
		}
		if (a * n + b == x + a) {
		    break;
		}
	}
}

// we just need to replace all ?'s with 1s
if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if x < n (we just need to replace one of the +?'s with +x, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && x < n && count.plus > 0) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = x;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b > 0 (we replace +?'s with +n's a times and one more +? with +b, the rest of the ?'s are 1s)
} else if (first_q > n && n > 1 && b > 0 && count.plus >= a + 1) {
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			if (rebus[i] == '+') {
				rebus[i + 1] = b;
				break;
			}
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

// if b == 0 (we replace +?'s with +n's a times, the rest of the ?'s are 1s')
} else if (first_q > n && n > 1 && count.plus >= a){
	rebus[0] = n;
	var counter = 0;
	for (var i = 1; i < rebus.length; i++)  {
		// I only want to replace +? with +n a times, the next replacement should be +b
		if (counter == a) {
			break;
		} else {
			if (rebus[i] == '+') {
				rebus[i + 1] = n;
				counter += 1;
			}
		}
	}

	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);

} else {
	print('Impossible');
}

/* checking stuff
print(JSON.stringify(count));
print(first_q);

print(n);
print(a);
print(b);
print(x);
*/

var rebus = readline().split(' ').map(String);

var count = {plus: 1, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

// Do I need to modify the -? or the +?s
var diff = 0;
var a = 0; // a --> change a number of ?'s to n
var b = 1; // b --> change another -? to b
var counter = 0; // used to count how many ?'s are replaced with n (count a)

// Modify 'minus' ?
if (count.plus - count.minus > n) {
	// modify 'minus'
	// minus_sum is what the sum of all -? needs to be
	var minus_sum = count.plus - n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (minus_sum >= count.minus && minus_sum <= count.minus * n) {

		diff = minus_sum - count.minus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		rebus[0] = 1;

		counter = 0;
		for (var i = 1; i < rebus.length; i++)  {
			// I only want to replace -? with -n a times, the next replacement should be -b, the rest should be 1
			if (counter == a) {
				if (rebus[i] == '-') {
					rebus[i + 1] = b;
					break;
				}
			} else {
				if (rebus[i] == '-') {
					rebus[i + 1] = n;
					counter += 1;
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}

} else {
	//modify 'plus'
	// plus_sum is what the sum of all +? needs to be
	var plus_sum = count.minus + n;
	// Checking to see if this sum falls between the number of -? and the number of -? * n
	if (plus_sum >= count.plus && plus_sum <= count.plus * n) {

		diff = plus_sum - count.plus;
		a = Math.floor(diff / (n - 1));
		b = diff % (n - 1) + 1;

		if (a === 0) {
			rebus[0] = b;
		} else if (a >= 1) {
			rebus[0] = n;
			counter = 1;
			for (var i = 1; i < rebus.length; i++)  {
				// I only want to replace +? with +n a times, the next replacement should be +b, the rest should be 1
				if (counter == a) {
					if (rebus[i] == '+') {
						rebus[i + 1] = b;
						break;
					}
				} else {
					if (rebus[i] == '+') {
						rebus[i + 1] = n;
						counter += 1;
					}
				}
			}
		}

		for (var i = 1; i < rebus.length; i++) {
			if (rebus[i] == '?') {
				rebus[i] = 1;
			}
		}

		rebus = rebus.join(' ');

		print('Possible');
		print(rebus);

	} else {
		print('Impossible');
	}
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q - 1 == n && n > 1) {
	rebus[0] = first_q - 1;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = 2;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}

var rebus = readline().split(' ').map(String);

var count = {plus: 0, minus: 0}; // number of + and - in rebus

for (var i = 0; i < rebus.length; i++) {
	if (rebus[i] == '+') {
		count.plus += 1;
	} else if (rebus[i] == '-') {
		count.minus += 1;
	}
	if (rebus[i] == '=') {
		n = Number(rebus[i + 1]);
	}
}

var first_q = n + count.minus - count.plus;

if (first_q > 0 && first_q <= n) {
	rebus[0] = first_q;
	for (var i = 2; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else if (first_q > n && n > 1) {
	rebus[0] = n;
	for (var i = 1; i < rebus.length; i++)  {
		if (rebus[i] == '+') {
			rebus[i + 1] = first_q - n + 1;
			break;
		}
	}
	for (var i = 1; i < rebus.length; i++) {
		if (rebus[i] == '?') {
			rebus[i] = 1;
		}
	}
	rebus = rebus.join(' ');

	print('Possible');
	print(rebus);
} else {
	print('Impossible');
}


var x = readline();

var a = "pq"+"bd"+"AHIMOoTUVvWwXxY";
var b = "qp"+"db"+"AHIMOoTUVvWwXxY";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)
{
    var m = a.indexOf(x[i]), n = b.indexOf(x[j]);
    ok = ok && m>=0 && m==n;
}

print(ok ? "TAK" : "NIE");

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if(str.length % 2){
        let char = str[Math.floor(str.length / 2)];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

var left = "bd" + "pq" + "AHIMOoTUVvWwXxY";
var right = "db" + "qp" + "AHIMOoTUVvWwXxY";

var x = readline();

var ok = true;

for (var i = 0, j = x.length - 1; i < x.length / 2 && ok; i++, j--) {
  var leftPosition = left.indexOf(x[i]);
  var rightPosition = right.indexOf(x[j]);

  ok = leftPosition >= 0 && leftPosition == rightPosition;
}

print(ok ? "TAK" : "NIE");

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'xx',
    'XX',
    'oo',
    'OO',
    'vv',
    'VV',
    'ww',
    'WW',
    'II',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
    'pq',
    'qp',
    'bd',
    'db',
  ]

  const isSPalindrome = s => {
    for (let i = 0; i < s.length / 2; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}

var x = readline();

var a = "pq"+"bd"+"AHIMOoTUVvWwXxYy";
var b = "qp"+"db"+"AHIMOoTUVvWwXxYy";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<=j ; i++, j--)
{
    var m = a.indexOf(x[i]), n = b.indexOf(x[j]);
    ok = ok && (m>=0 && m == n);
}

print(ok?"TAK":"NIE");

var x = readline();

var a="pqbd";
var b="qpdb";

var ok = true;
for (var i=0, j=x.length-1 ; ok && i<j ; i++, j--)
{
    ok = ok && (
        (x[i]==x[j] && "AHIMOoTUVvWwXxYy".includes(x[i]))
        || a.indexOf(x[i])==b.indexOf(x[j])
    );
}

print(ok?"TAK":"NIE");

var left = "bd" + "pq" + "AHIMOoTUVWwXxY";
var right = "db" + "qp" + "AHIMOoTUVWwXxY";

var x = readline();

var ok = true;

for (var i = 0, j = x.length - 1; i < x.length / 2 && ok; i++, j--) {
  var leftPosition = left.indexOf(x[i]);
  var rightPosition = right.indexOf(x[j]);

  ok = ok && leftPosition >= 0 && leftPosition == rightPosition;
}

print(ok ? "TAK" : "NIE");

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if( str.length % 2){
        let char = str[Math.floor(str.length) / 2];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    if( str.length % 2 !== 1)
        return "NIE";

    for(let i = 0; i < Math.floor(str.length) / 2; i++)
        if(str[i] !== str[str.length - i - 1])
            return "NIE";

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;
const INF = Math.pow(10, 12);

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

const getInput = () => {
    const lineInput = readline();
    return lineInput;
};

const isSPalindrom = (str) => {
    const symmetric = "AHIMOoTUVvWwXxY";

    if( str.length % 2 !== 1){
        let char = str[Math.floor(str.length) / 2];
        if(!symmetric.includes(char))
            return "NIE";
    }

    for(let i = 0; i < Math.floor(str.length) / 2; i++){
        if(str[i] === "p" && str[str.length - i - 1] === "q")
            continue;
        if(str[i] === "q" && str[str.length - i - 1] === "p")
            continue;
        if(str[i] === "b" && str[str.length - i - 1] === "d")
            continue;
        if(str[i] === "d" && str[str.length - i - 1] === "b")
            continue;

        if(symmetric.includes(str[i]) && symmetric.includes(str[str.length - i - 1])){
            if(str[i] === str[str.length - i - 1])
                continue;
        }

        return "NIE";
    }

    return "TAK";
}

function main() {
    const input = getInput();
    const result = isSPalindrom(input);
    console.log(result);
}

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'll',
    'xx',
    'XX',
    'ii',
    'II',
    'oo',
    'OO',
    'vv',
    'VV',
    'ww',
    'WW',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
    'pq',
    'qp',
    'bd',
    'db',
  ]

  const isSPalindrome = s => {
    for (let i = 0; i < s.length / 2; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}

const readline = require('readline')
const rl = readline.createInterface(process.stdin, process.stdout)

const input = []

rl.on('line', line => input.push(line.toString()))

rl.on('close', () => {
  solve()
})

const solve = () => {
  const mirrorAlphabetPairs = [
    'xx',
    'bd',
    'db',
    'ii',
    'll',
    'oo',
    'vv',
    'ww',
    'pq',
    'qp',
    'XX',
    'II',
    'OO',
    'VV',
    'WW',
    'TT',
    'HH',
    'MM',
    'YY',
    'UU',
    'AA',
  ]

  const isSPalindrome = s => {
    const upperLimit = Math.floor(s.length / 2)

    for (let i = 0; i < upperLimit; i++) {
      const j = s.length - 1 - i
      const pair = s[i] + s[j]

      if (!mirrorAlphabetPairs.includes(pair)) {
        return false
      }
    }

    return true
  }

  const [s] = input
  const output = isSPalindrome(s) ? 'TAK' : 'NIE'

  console.log(output)
}