process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

process.stdin.on("data", rawData => {
  standardInputString += rawData;
});

process.stdin.on("end", _ => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map(line => {
      return line.trim();
    });

  main();
});

// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A

// function main() {
//   const testQuantity = +readLine();
//   for (let testNumber = 0; testNumber < testQuantity; testNumber++) {
//     let inputString = readLine();
//     let curLen = 0;
//     let curPrefix = "";
//     let maxPrefixLen = 0;

//     for (let inputChar of inputString) {
//       curPrefix += inputChar;
//       curLen++;

//       let foundNew = true;
//       let medianIndex = Math.floor(curLen / 2);
//       for (; medianIndex >= 0; medianIndex--) {
//         if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {
//           foundNew = false;
//           break;
//         }
//       }

//       if (foundNew) {
//         maxPrefixLen = curLen;
//       }
//     }

//     console.log(maxPrefixLen);
//   }
// }

// .. -> Problem B

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     let counter = 0;

//     for (let curLen = 0; curLen <= inputStr.length; curLen++) {
//       for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {
//         let substring = inputStr.substring(startIx, startIx + curLen);
//         let prefix = inputStr.substring(0, curLen);
//         let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);

//         if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {
//           counter++;
//         }
//       }
//     }

//     console.log(counter);
//   }
// }

// .. -> Problem C

// function match(text, pattern) {
//   if (pattern.length > text.length) {
//     return false;
//   }

//   for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {
//     if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== "?") {
//       return false;
//     }
//   }

//   return true;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     const entryIndexes = [];

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {
//         entryIndexes.push(startIx);
//       }
//     }

//     console.log(entryIndexes.length);
//     console.log(entryIndexes.join(" "));
//   }
// }

// .. -> Problem D

// function getSubstrQuan(length) {
//   return (length + 1) * (length) / 2;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     let entryBorders = [];
//     let counter = 0;

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {
//         entryBorders.push([startIx, startIx + inputPattern.length - 1]);
//       }
//     }

//     entryBorders.push([inputStr.length, inputStr.length]);
//     let lastLeftBorder = 0;
//     for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {
//       let curPair = entryBorders[pairIx];
//       let curSubstrLen = curPair[1] - lastLeftBorder;
//       counter += getSubstrQuan(curSubstrLen);
//       lastLeftBorder = curPair[0] + 1;

//       if (curPair[1] - curPair[0] - 1 > 0) {
//         counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);
//       }
//     }

//     console.log(counter);
//   }
// }

// Codeforces Round #698 (Div. 2) -> Problem A

// function main() {
//   let testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     let n = +readLine();
//     let a = readLine().split(" ");
//     a = a.map(item => +item);
//     let counterArr = [];
//     for (let i = 0; i <= n; i++) counterArr[i] = 0;

//     for (let el of a) {
//       counterArr[el]++;
//     }

//     console.log(Math.max(...counterArr));
//   }
// }

// .. -> Problem B

function main() {
  const testQuan = +readLine();
  for (let testIx = 0; testIx < testQuan; testIx++) {
    let [, d] = readLine().split(" ").map(item => +item);
    let a = readLine().split(" ").map(item => +item);

    let possibleLastDigits = [];
    for (let multiplier = 1; multiplier < 11; multiplier++) {
      possibleLastDigits.push(d * multiplier % 10);
    }

    let canGain = num => {
      let curLastDigit = num % 10;
      let multiplier = possibleLastDigits.indexOf(curLastDigit) + 1;

      return multiplier ? multiplier * d <= num : false;
    };

    for (let item of a) {
      let flag = canGain(item) || String(item).includes(`${d}`);
      // console.log(item + ", " + flag);
      for (let i = 0; i < 10; i++) {
        let tmp = item;
        // console.log(tmp, i);
        tmp -= d * 10 + i;
        // console.log(tmp);

        if (tmp > 0) {
          flag = flag || canGain(tmp);
        }
        // console.log(flag);
      }

      console.log(flag ? "YES" : "NO");
    }
  }
}

// .. -> Problem C

// function main() {

// }

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var d = nextInt();
		for(var j = 0; j < N; j++){
			var a = nextInt();
			if(a % d == 0){
				myout("YES");
				continue;
			}
			var tmp = a;
			var isOK = false;
			while(tmp > 0){
				if(tmp % 10 == d){
					isOK = true;
					break;
				}
				tmp = Math.floor(tmp / 10);
			}
			var p = a % d;
			for(var k = 1; k <= Math.floor(a / d); k++){
				var tmp = (k * d + p);
				while(tmp > 0){
					if(tmp % 10 == d){
						isOK = true;
						break;
					}
					tmp = Math.floor(tmp / 10);
				}
				if(isOK){
					break;
				}
			}

			if(isOK){
				myout("YES");
			}else{
				myout("NO");
			}
		}
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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++];
}
/**
2
3 7
24 25 27
10 7
51 52 53 54 55 56 57 58 59 60
**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let [q, d] = readline().split(" ");
    let a = readline().split(" ");
    let map = {};

    for(let i=0;i<a.length;i++) {
        if(a[i].includes(d)) {
            map[a[i]] = 'Yes';
            console.log('Yes');
        } else {
            let number = Number(d);
            let current = Number(a[i]);
            let found = false;
            while(!found && current > number) {
                current = current - number;

                if (map[current]) {
                    console.log(map[current]);
                    found = true;
                }else if (("" + current).includes(d)) {
                    map[current] = 'Yes';

                    console.log(map[current]);
                    found = true;
                }
            }

            if(found === false) {
                map[a[i]] = 'No';
                console.log("No");
            }
        }
    }

}

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', () => {
  inputString = inputString.split('\n').map(str => str.trim());

  main();
});

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

function main() {
  let t = readline();

  while (t--) {
    const d = readline().split(' ').map(num => parseInt(num, 10))[1];
    const q = readline().split(' ').map(num => parseInt(num, 10));

    q.forEach(n => {
      let r = '';

      for (let i = n; i > 0; i -= d) {
        const iar = `${i}`.includes(d);

        if (iar) {
          r = 'YES';
          break;
        } else {
          r = 'NO';
        }
      }

      console.log(r);
    });
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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++];
}

// Make a Snippet for the code above this and then write your logic in main();

function main() {
    const x = readline();
    var answer = []

    // console.log(Number(x))
    // 1 1 7
    // 6 9, 15, 18
    Array(Number(x)).fill(1).map((t, i) => {
        var [q, d] = readline().split(' ').map(x => Number(x));
        var array = readline().split(' ').map(x => Number(x));
        var answer = {}
        for (var i = 0; i < 100; i++) {
            answer[i] = true
        }
        for (var i = 0; i < 100; i++) {
            answer[i * d] = false
            answer[i * d + Number(`1${d}`)] = false
            answer[i * d + Number(`2${d}`)] = false
            answer[i * d + Number(`3${d}`)] = false
            answer[i * d + Number(`4${d}`)] = false
            answer[i * d + Number(`5${d}`)] = false
            answer[i * d + Number(`6${d}`)] = false
            answer[i * d + Number(`7${d}`)] = false
            answer[i * d + Number(`8${d}`)] = false
            answer[i * d + Number(`9${d}`)] = false
            answer[i * d + Number(`${d}0`)] = false
            answer[i * d + Number(`${d}1`)] = false
            answer[i * d + Number(`${d}2`)] = false
            answer[i * d + Number(`${d}3`)] = false
            answer[i * d + Number(`${d}4`)] = false
            answer[i * d + Number(`${d}5`)] = false
            answer[i * d + Number(`${d}6`)] = false
            answer[i * d + Number(`${d}7`)] = false
            answer[i * d + Number(`${d}8`)] = false
            answer[i * d + Number(`${d}9`)] = false
        }
        // console.log(answer)
        // for (var i = 0; i < 100; i++) {
        //     if (answer[i]) console.log(i)
        // }
        array.map((x,i)=>{
        console.log(!answer[x] ? 'YES':'NO')
        })

    })

}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let temp = readline().split(" ").map(x => parseInt(x));
    let length = temp[0];
    let d = temp[1];
    let input = readline().split(" ");

    let obj = {
        "0" : null,
        "1" : null,
        "2" : null,
        "3" : null,
        "4" : null,
        "5" : null,
        "6" : null,
        "7" : null,
        "8" : null,
        "9" : null,
    };

    for(let i = 1; i < 11; i++){
        let t = String(i * d)
        if(obj[t[t.length - 1]] === null){
            obj[t[t.length - 1]] = parseInt(t);
        }
    }

    for(let i = 0; i < length; i++){
        let t = input[i][input[i].length - 1];
        if(obj[t] === null){
            if(parseInt(input[i]) > d * 10){
                print("YES");
            } else {
                print("NO")
            }
        } else if(obj[t] <= parseInt(input[i])){
            print("YES")
        } else {
            print("NO")
        }
    }
}

function solve(a,n){
    var l = 0;

    while(l < a.length){
        var f = true;
        if(String(a[l]).includes(String(n))){
            write("YES\n");
        }else{
            var aux = a[l];
            while(aux > 0){
                aux = aux - Number(n);
                if(String(aux).includes(String(n))){
                    write("YES\n");
                    f = false;
                    break;
                }
            }
            if(f){
                write("NO\n");
            }
        }
        l++;
    }

}

var a = [];
var t = Number(readline());
for (var i = 0; i<t;i++){
    n = readline().split(' ').map((x) => x);
    a = readline().split(' ').map((x) => x);
    solve(a,n[1]);
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
const solve = () => {
  let t = parseInt(readline());
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (arr[i] >= d * 10) console.log("YES");
      else {
        let flag = false;
        let k = arr[i];
        while (k > 0) {
          if (precheck(k, d)) {
            flag = true;
            break;
          }
          k = k - d;
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
let dp = [];
const precompute = () => {
  for (let i = 2; i <= 9; i++) {
    let k = [];
    for (let j = 0; j <= 9; j++) {
      k.push(i * (j + 1));
    }
    dp.push(k);
  }
};
const solve = () => {
  let t = parseInt(readline());
  precompute();
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (precheck(arr[i], d)) console.log("YES");
      else {
        let flag = false;
        for (let j = 0; j <= 9; j++) {
          if (dp[d - 2][j] % 10 === arr[i] % 10) {
            if (arr[i] >= dp[d - 2][j]) {
              flag = true;
              break;
            }
          }
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
let dp = [];
const precompute = () => {
  for (let i = 2; i <= 9; i++) {
    let k = [];
    for (let j = 0; j <= 9; j++) {
      k.push(i * (j + 1));
    }
    dp.push(k);
  }
};
const solve = () => {
  let t = parseInt(readline());
  precompute();
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (precheck(arr[i], d)) console.log("YES");
      else {
        let flag = false;
        for (let j = 0; j <= 9; j++) {
          if (dp[d - 2][j] % 10 === arr[i] % 10) {
            flag = dp[d - 2][j] <= arr[i] ? true : false;
          }
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
let dp = [];
const precompute = () => {
  for (let i = 2; i <= 9; i++) {
    let k = [];
    for (let j = 0; j <= 9; j++) {
      k.push(i * (j + 1));
    }
    dp.push(k);
  }
};
const solve = () => {
  let t = parseInt(readline());
  precompute();
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (precheck(arr[i], d)) console.log("YES");
      else {
        let flag = false;
        for (let j = 0; j <= 9; j++) {
          if (dp[d - 2][j] % 10 === arr[i] % 10) {
            flag = dp[d - 2][j] <= arr[i] ? true : false;
            break;
          }
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
let dp = [];
const precompute = () => {
  for (let i = 2; i <= 9; i++) {
    let k = [];
    for (let j = 0; j <= 9; j++) {
      k.push(i * (j + 1));
    }
    dp.push(k);
  }
};
const solve = () => {
  let t = parseInt(readline());
  precompute();
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (precheck(arr[i], d)) console.log("YES");
      else {
        let flag = false;
        for (let j = 0; j < 9; j++) {
          if (dp[d - 2][j] % 10 === arr[i] % 10) {
            flag = dp[d - 2][j] <= arr[i] ? true : false;
            break;
          }
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}
let dp = [];
const precompute = () => {
  for (let i = 2; i <= 9; i++) {
    let k = [];
    for (let j = 0; j < 9; j++) {
      k.push(i * (j + 1));
    }
    dp.push(k);
  }
};
const solve = () => {
  let t = parseInt(readline());
  precompute();
  const precheck = (n, d) => {
    while (n > 0) {
      if (n % 10 === d) return true;
      n = Math.floor(n / 10);
    }
    return false;
  };
  while (t--) {
    let [n, d] = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    for (let i = 0; i < n; i++) {
      if (d === 1) console.log("YES");
      else if (precheck(arr[i], d)) console.log("YES");
      else {
        let flag = false;
        for (let j = 0; j < 9; j++) {
          if (dp[d - 2][j] % 10 === arr[i] % 10) {
            flag = dp[d - 2][j] <= arr[i] ? true : false;
            break;
          }
        }
        console.log(`${flag === true ? "YES" : "NO"}`);
      }
    }
  }
};
solve();

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var d = nextInt();
		for(var j = 0; j < N; j++){
			var a = nextInt();
			if(a % d == 0){
				myout("YES");
				continue;
			}
			var tmp = a;
			var isOK = false;
			while(tmp > 0){
				if(tmp % 10 == d){
					isOK = true;
					break;
				}
				tmp = Math.floor(tmp / 10);
			}
			var p = a % d;
			for(var k = 1; k <= Math.min(100, Math.floor(a / d)); k++){
				if((k * d + p) % 10 == d){
					isOK = true;
					break;
				}
			}

			if(isOK){
				myout("YES");
			}else{
				myout("NO");
			}
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var d = nextInt();
		for(var j = 0; j < N; j++){
			var a = nextInt();
			if(a % d == 0){
				myout("YES");
				continue;
			}
			var tmp = a;
			var isOK = false;
			while(tmp > 0){
				if(tmp % 10 == d){
					isOK = true;
					break;
				}
				tmp = Math.floor(tmp / 10);
			}
			var p = a % d;
			for(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){
				if((k * d + p) % 10 == d){
					isOK = true;
					break;
				}
			}

			if(isOK){
				myout("YES");
			}else{
				myout("NO");
			}
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var d = nextInt();
		for(var j = 0; j < N; j++){
			var a = nextInt();
			if(a % d == 0){
				myout("YES");
				continue;
			}
			var tmp = a;
			var isOK = false;
			while(tmp > 0){
				if(tmp % d == 0){
					isOK = true;
					break;
				}
				tmp = Math.floor(tmp / 10);
			}
			var p = a % d;
			for(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){
				if((k * d + p) % 10 == d){
					isOK = true;
					break;
				}
			}

			if(isOK){
				myout("YES");
			}else{
				myout("NO");
			}
		}
	}
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var d = nextInt();
		for(var j = 0; j < N; j++){
			var a = nextInt();
			if(a % 10 == d || a % d == 0){
				myout("YES");
				continue;
			}
			var tmp = a;
			var isOK = false;
			while(tmp > 0){
				if(tmp % d == 0){
					isOK = true;
					break;
				}
				tmp = Math.floor(tmp / 10);
			}
			var p = a % d;
			for(var k = 1; k <= Math.min(9, Math.floor(a / d)); k++){
				if((k * d + p) % 10 == d){
					isOK = true;
					break;
				}
			}

			if(d + p == 10){
				isOK = true;
			}
			if(isOK){
				myout("YES");
			}else{
				myout("NO");
			}
		}
	}
}

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

process.stdin.on("data", rawData => {
  standardInputString += rawData;
});

process.stdin.on("end", _ => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map(line => {
      return line.trim();
    });

  main();
});

// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A

// function main() {
//   const testQuantity = +readLine();
//   for (let testNumber = 0; testNumber < testQuantity; testNumber++) {
//     let inputString = readLine();
//     let curLen = 0;
//     let curPrefix = "";
//     let maxPrefixLen = 0;

//     for (let inputChar of inputString) {
//       curPrefix += inputChar;
//       curLen++;

//       let foundNew = true;
//       let medianIndex = Math.floor(curLen / 2);
//       for (; medianIndex >= 0; medianIndex--) {
//         if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {
//           foundNew = false;
//           break;
//         }
//       }

//       if (foundNew) {
//         maxPrefixLen = curLen;
//       }
//     }

//     console.log(maxPrefixLen);
//   }
// }

// .. -> Problem B

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     let counter = 0;

//     for (let curLen = 0; curLen <= inputStr.length; curLen++) {
//       for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {
//         let substring = inputStr.substring(startIx, startIx + curLen);
//         let prefix = inputStr.substring(0, curLen);
//         let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);

//         if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {
//           counter++;
//         }
//       }
//     }

//     console.log(counter);
//   }
// }

// .. -> Problem C

// function match(text, pattern) {
//   if (pattern.length > text.length) {
//     return false;
//   }

//   for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {
//     if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== "?") {
//       return false;
//     }
//   }

//   return true;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     const entryIndexes = [];

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {
//         entryIndexes.push(startIx);
//       }
//     }

//     console.log(entryIndexes.length);
//     console.log(entryIndexes.join(" "));
//   }
// }

// .. -> Problem D

// function getSubstrQuan(length) {
//   return (length + 1) * (length) / 2;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     let entryBorders = [];
//     let counter = 0;

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {
//         entryBorders.push([startIx, startIx + inputPattern.length - 1]);
//       }
//     }

//     entryBorders.push([inputStr.length, inputStr.length]);
//     let lastLeftBorder = 0;
//     for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {
//       let curPair = entryBorders[pairIx];
//       let curSubstrLen = curPair[1] - lastLeftBorder;
//       counter += getSubstrQuan(curSubstrLen);
//       lastLeftBorder = curPair[0] + 1;

//       if (curPair[1] - curPair[0] - 1 > 0) {
//         counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);
//       }
//     }

//     console.log(counter);
//   }
// }

// Codeforces Round #698 (Div. 2) -> Problem A

// function main() {
//   let testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     let n = +readLine();
//     let a = readLine().split(" ");
//     a = a.map(item => +item);
//     let counterArr = [];
//     for (let i = 0; i <= n; i++) counterArr[i] = 0;

//     for (let el of a) {
//       counterArr[el]++;
//     }

//     console.log(Math.max(...counterArr));
//   }
// }

// .. -> Problem B

function main() {
  let testQuan = +readLine();
  for (let testIx = 0; testIx < testQuan; testIx++) {
    let [d, q] = readLine().split(" ").map(item => +item);
    let a = readLine().split(" ").map(item => +item);
    let possibleLastDigits = [];

    for (let multiplier = 1; multiplier < 11; multiplier++) {
      possibleLastDigits.push(multiplier * q % 10);
    }

    for (let el of a) {
      let curLastDigit = el % 10;

      if (q % 2 === 0 && el % 2 === 1) {
        el -= q * 10 + curLastDigit;

        if (el < 0) {
          console.log("NO");
          continue;
        } else if (el === 0) {
          console.log("YES");
          continue;
        }
      }

      curLastDigit = el % 10;
      let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;

      if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {
        console.log("NO");
        continue;
      }

      console.log("YES");
    }
  }
}

// .. -> Problem C

// function main() {

// }

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

process.stdin.on("data", rawData => {
  standardInputString += rawData;
});

process.stdin.on("end", _ => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map(line => {
      return line.trim();
    });

  main();
});

// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A

// function main() {
//   const testQuantity = +readLine();
//   for (let testNumber = 0; testNumber < testQuantity; testNumber++) {
//     let inputString = readLine();
//     let curLen = 0;
//     let curPrefix = "";
//     let maxPrefixLen = 0;

//     for (let inputChar of inputString) {
//       curPrefix += inputChar;
//       curLen++;

//       let foundNew = true;
//       let medianIndex = Math.floor(curLen / 2);
//       for (; medianIndex >= 0; medianIndex--) {
//         if (curPrefix[curLen - 1 - medianIndex] !== curPrefix[medianIndex]) {
//           foundNew = false;
//           break;
//         }
//       }

//       if (foundNew) {
//         maxPrefixLen = curLen;
//       }
//     }

//     console.log(maxPrefixLen);
//   }
// }

// .. -> Problem B

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     let counter = 0;

//     for (let curLen = 0; curLen <= inputStr.length; curLen++) {
//       for (let startIx = 0; curLen + startIx <= inputStr.length; startIx++) {
//         let substring = inputStr.substring(startIx, startIx + curLen);
//         let prefix = inputStr.substring(0, curLen);
//         let suffix = inputStr.slice(inputStr.length - curLen, inputStr.length);

//         if (substring === prefix && substring !== suffix || substring === suffix && substring !== prefix) {
//           counter++;
//         }
//       }
//     }

//     console.log(counter);
//   }
// }

// .. -> Problem C

// function match(text, pattern) {
//   if (pattern.length > text.length) {
//     return false;
//   }

//   for (let comparingIx = 0; comparingIx < text.length; comparingIx++) {
//     if (text[comparingIx] !== pattern[comparingIx] && pattern[comparingIx] !== "?") {
//       return false;
//     }
//   }

//   return true;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     const entryIndexes = [];

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( match(inputStr.slice(startIx, startIx + inputPattern.length), inputPattern) ) {
//         entryIndexes.push(startIx);
//       }
//     }

//     console.log(entryIndexes.length);
//     console.log(entryIndexes.join(" "));
//   }
// }

// .. -> Problem D

// function getSubstrQuan(length) {
//   return (length + 1) * (length) / 2;
// }

// function main() {
//   const testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     const inputStr = readLine();
//     const inputPattern = readLine();
//     let entryBorders = [];
//     let counter = 0;

//     for (let startIx = 0; startIx + inputPattern.length <= inputStr.length; startIx++) {
//       if ( inputStr.slice(startIx, startIx + inputPattern.length).includes(inputPattern) ) {
//         entryBorders.push([startIx, startIx + inputPattern.length - 1]);
//       }
//     }

//     entryBorders.push([inputStr.length, inputStr.length]);
//     let lastLeftBorder = 0;
//     for (let pairIx = 0; pairIx < entryBorders.length; pairIx++) {
//       let curPair = entryBorders[pairIx];
//       let curSubstrLen = curPair[1] - lastLeftBorder;
//       counter += getSubstrQuan(curSubstrLen);
//       lastLeftBorder = curPair[0] + 1;

//       if (curPair[1] - curPair[0] - 1 > 0) {
//         counter -= getSubstrQuan(curPair[1] - curPair[0] - 1);
//       }
//     }

//     console.log(counter);
//   }
// }

// Codeforces Round #698 (Div. 2) -> Problem A

// function main() {
//   let testQuan = +readLine();
//   for (let testIx = 0; testIx < testQuan; testIx++) {
//     let n = +readLine();
//     let a = readLine().split(" ");
//     a = a.map(item => +item);
//     let counterArr = [];
//     for (let i = 0; i <= n; i++) counterArr[i] = 0;

//     for (let el of a) {
//       counterArr[el]++;
//     }

//     console.log(Math.max(...counterArr));
//   }
// }

// .. -> Problem B

function main() {
  let testQuan = +readLine();
  for (let testIx = 0; testIx < testQuan; testIx++) {
    let [d, q] = readLine().split(" ").map(item => +item);
    let a = readLine().split(" ").map(item => +item);
    let possibleLastDigits = [];

    for (let multiplier = 1; multiplier < 11; multiplier++) {
      possibleLastDigits.push(multiplier * q % 10);
    }

    for (let el of a) {
      let curLastDigit = el % 10;

      if (q % 2 === 0 && el % 2 === 1) {
        el -= q * 10 + curLastDigit;

        if (el < 0) {
          console.log("NO");
          continue;
        }
      }

      curLastDigit = el % 10;
      let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;

      if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {
        console.log("NO");
        continue;
      }

      console.log("YES");
    }
  }
}

// .. -> Problem C

// function main() {

// }

process.stdin.resume();
process.stdin.setEncoding("utf8");
let standardInputString = "";
let curLine = 0;

function readLine() {
  return standardInputString[curLine++];
}

process.stdin.on("data", rawData => {
  standardInputString += rawData;
});

process.stdin.on("end", _ => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map(line => {
      return line.trim();
    });

  main();
});

// Pilot course from ITMO -> Z-function -> Step 1 -> Problem A

// function main() {
//   const testQuantity = +readLine();
//   for (let testNumber = 0; testNumber < testQuantity; testNumber++) {
//     let inputString = readLine();
//     let curLen = 0;
//     let curPrefix = "";
//     let maxPrefixLen = 0;

// .. -> Problem B

function main() {
  let testQuan = +readLine();
  for (let testIx = 0; testIx < testQuan; testIx++) {
    let [d, q] = readLine().split(" ").map(item => +item);
    let a = readLine().split(" ").map(item => +item);
    let possibleLastDigits = [];

    for (let multiplier = 1; multiplier < 11; multiplier++) {
      possibleLastDigits.push(multiplier * q % 10);
    }

    for (let el of a) {
      let curLastDigit = el % 10;
      let luckyNumsQuan = possibleLastDigits.indexOf(curLastDigit) + 1;

      if ( !possibleLastDigits.includes(curLastDigit) || luckyNumsQuan === -1 || luckyNumsQuan * q > el ) {
        console.log("NO");
        continue;
      }

      console.log("YES");
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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++];
}
/**
2
3 7
24 25 27
10 7
51 52 53 54 55 56 57 58 59 60
**/

function gcd(a, b) {
    if (!b) {
        return a;
    }

    return gcd(b, a % b);
};

function lcm(a, b) {
    return (a / gcd(a, b) * b);
}

function main() {
    let n = Number(readline());

    for(let r=0;r<n;r++) {
        solve();
    }

}

function solve() {
    let [q, d] = readline().split(" ");
    let a = readline().split(" ");

    let map = {};

    for(let i=0;i<a.length;i++) {
        if(a[i].includes(d)) {
            console.log('Yes');
        } else {
            let number = Number(d);
            let current = Number(a[i]);
            let found = false;
            while(!found && current > number) {
                current = current - number;

                if(map[current]) {
                    console.log(map[current]);
                    found = true;
                }

                if (("" + current).includes(d)) {
                    map[current] = 'Yes';
                    console.log(map[current]);
                    found = true;
                }
            }

            if(found === false) {
                map[a[i]] = 'No';
                console.log("No");
            }
        }
    }

}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let temp = readline().split(" ").map(x => parseInt(x));
    let length = temp[0];
    let d = temp[1];
    let input = readline().split(" ");

    let obj = {
        "0" : null,
        "1" : null,
        "2" : null,
        "3" : null,
        "4" : null,
        "5" : null,
        "6" : null,
        "7" : null,
        "8" : null,
        "9" : null,
    };

    for(let i = 1; i < 11; i++){
        let t = String(i * d)
        if(obj[t[t.length - 1]] === null){
            obj[t[t.length - 1]] = parseInt(t);
        }
    }

    for(let i = 0; i < length; i++){
        let t = input[i][input[i].length - 1];
        if(obj[t] === null){
            let a = input[i] % (d * 10);
            let b = Math.trunc(input[i] / (d * 10))
            if(a % b === 0){
                print("YES");
            } else {
                print("NO")
            }
        } else if(obj[t] <= parseInt(input[i])){
            print("YES")
        } else {
            print("NO")
        }
    }
}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let temp = readline().split(" ").map(x => parseInt(x));
    let length = temp[0];
    let d = temp[1];
    let input = readline().split(" ");

    let obj = {
        "0" : null,
        "1" : null,
        "2" : null,
        "3" : null,
        "4" : null,
        "5" : null,
        "6" : null,
        "7" : null,
        "8" : null,
        "9" : null,
    };

    for(let i = 1; i < 11; i++){
        let t = String(i * d)
        if(obj[t[t.length - 1]] === null){
            obj[t[t.length - 1]] = parseInt(t);
        }
    }

    for(let i = 0; i < length; i++){
        let t = input[i][input[i].length - 1];
        if(obj[t] === null){
            let a = input[i] % (d * 10);
            let b = Math.trunc(input[i] / (d * 10))
            if(a < b * 9){
                print("YES");
            } else {
                print("NO")
            }
        } else if(obj[t] <= parseInt(input[i])){
            print("YES")
        } else {
            print("NO")
        }
    }
}

"use strict"

let iter = parseInt(readline());

while(iter--){
    let temp = readline().split(" ").map(x => parseInt(x));
    let length = temp[0];
    let d = temp[1];
    let input = readline().split(" ");

    let obj = {
        "0" : null,
        "1" : null,
        "2" : null,
        "3" : null,
        "4" : null,
        "5" : null,
        "6" : null,
        "7" : null,
        "8" : null,
        "9" : null,
    };

    for(let i = 1; i < 11; i++){
        let t = String(i * d)
        if(obj[t[t.length - 1]] === null){
            obj[t[t.length - 1]] = parseInt(t);
        }
    }

    for(let i = 0; i < length; i++){
        let t = input[i][input[i].length - 1];
        if(obj[t] !== null && obj[t] <= parseInt(input[i])){
            print("YES")
        } else {
            print("NO")
        }
    }
}


//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	var mod = 998244353;
	while(hasNext()){
		var N = nextInt();
		if(N % 2 == 1){
			myout(0);
			continue;
		}
		var v = 1;
		for(var i = 1; i <= N / 2; i++){
			v *= i;
			v %= mod;
			v *= i;
			v %= mod;
		}
		myout(v);
	}
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

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

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

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        const mod = 998244353;
        let n = parseInt(readline(), 10);

        if (n % 2 === 1) {
            output(0);
            continue;
        }

        let m = n / 2;
        let res = 1;
        for (let i = 1; i <= m; i++) {
            res *= i;
            res = res % mod;
        }

        let one = BigInt(res);
        let modd = BigInt(mod);
        let result = (one * one) % modd;

        output(result.toString());
    }
}

// problems/contest1658/B/src/ts/solution.ts
var lines = [];
require("readline").createInterface({
  input: process.stdin
}).on("line", (line) => lines.push(line));
process.stdin.on("end", () => {
  main(lines);
});
var MOD = 998244353;
var mul = (a, b) => Number(BigInt(a) * BigInt(b) % BigInt(MOD));
function main(lines2) {
  let i = 0;
  for (let t = Number(lines2[i++]); t > 0; t--) {
    const n = Number(lines2[i++]);
    console.log(solve(n));
  }
}
function fac(n) {
  let res = 1;
  for (let i = 1; i <= n; i++)
    res = mul(res, i);
  return res;
}
function solve(n) {
  if (n % 2 !== 0)
    return 0;
  const m = fac(n / 2);
  return mul(m, m);
}

const fs = require('fs')
const inputs = fs.readFileSync(0, 'utf-8').split('\n')
const N = Number(inputs[0])
for (let _ = 0, __ = 1; _ < N; _++) {
  const n = Number(inputs[__++])
  main(n)
}

function main(n) {
  const MOD = BigInt(998244353)
  if (n & 1) {
    console.log(0)
  } else {
    let res = 1n
    n = BigInt(n / 2)
    while (n) {
      res *= n--
    }
    res = res * res
    console.log(Number(res % MOD))
  }
}

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        output[i] = solve(n)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n) {
    if (n & 1) return 0

    n /= 2
    let now = 1
    for (let i = 1; i <= n; i++) {
        now = mul(now, i)
    }
    return mul(now, now)
}

const MOD = 998244353
const MOD_CUT = ((1 << 20) * (1 << 20)) % MOD
function add(a, b) {
    return (a + b) % MOD
}
function minus(a, b) {
    return add(add(a, -b), MOD)
}
function mul(a, b) {
    let r = (a >> 20) * (b >> 20) * MOD_CUT
        + (a & 0xfff00000) * (b & 0xfffff)
        + (a & 0xfffff) * b
    return r % MOD
}
function pow(a, b) {
    let r = 1
    let base = a
    while (b) {
        if (b & 1) {
            r = mul(r, base)
        }
        b >>= 1
        base = mul(base, base)
    }
    return r
}

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline();

  if (n % 2 !== 0) print(0);
  else {
    n = n / 2;
    var ans = 1;
    for (var j = n; j > 0; j--) {
      ans *= j * j % 998244353;
      ans %= 998244353;
    }
    print(ans);
  }
}

var t = readline();

for (var i = 0; i < t; i++) {
  var n = readline();

  if (n % 2 !== 0) print(0);
  else {
    n = Math.floor(n / 2);
    var ans = 1;
    for (var j = 1; j <= n; j++) {
      ans = (ans * j) % 998244353;
    }
    ans = (ans * ans) % 998244353;
    print(ans);
  }
}


var testAmount = parseInt(readline());

var wrapperAmounts = [];
for (var i = 0; i < testAmount; i++) {
  wrapperAmounts.push(parseInt(readline()));
}

for (var i = 0; i < wrapperAmounts.length; i++) {
  for (var k = 2; k <= 29; k++) {
    var x = wrapperAmounts[i] / (Math.pow(2, k) - 1);
    if (x === Math.floor(x)) {
      print(x);
      break;
    }
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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++];
}
// Make a Snippet for the code above this and then write your logic in main();

function main() {
  //let [n, industry] = readline().split(" ").map(e => parseInt(e));

    let cases = parseInt(readline(), 10);
    for (var i = 0; i < cases; i++) {
      let d = [1,2]
      let sum = 3;
      const p = parseInt(readline(), 10);

      while (p % sum != 0) {
        d.push(d[d.length-1]*2);
        sum = d.reduce((a,b) => a+b, 0);
      }

      console.log(p / sum);
    }

}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else if (n % 7 == 0) print(n / 7);
  else {
    var k = 2;
    var flag = true;
    while (flag == true) {
      var x = n / (Math.pow(2, k) - 1);

      if (x == Math.floor(x) && x > 0) {
        print(x);
        flag = false;
      }
      k++;
    }
  }
}

r=readline
n=+r()
while(n--){
    t=+r()
    for(i=2;i<t;i++)
    {
        p=Math.pow(2,i)-1
        if(t%p==0)
        {
            print(t/p)
            break
        }
    }
}

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);
	for(var i = 0; i < t; i++){
		var n = nextInt();
		var k = 2;
		var count = 3;
		while(true){
			if(n % count == 0){
				break;
			}
			k++;
			count += Math.pow(2,k - 1);
		}
		output[i] = n / count;
	}
	myout(myconv(output,9));
}

var n = Number(readline());
var inp;
for(var i = 0; i < n; i++){
    inp = Number(readline());
    var k = 3;
    while(inp%k !== 0){
    k = k*2 + 1
    }
    print(inp/k)

}

var t = parseInt(readline());

for(var qq = 0; qq < t; qq++) {
    var n = parseInt(readline());

    var k = 2;

    while (true) {
        var kk = (1 << k);
        var del = kk - 1;

        if (n === del || n % del === 0) {
            break;
        }
        k++;
    }

    var kkk = (1 << k);
    var x = n / (kkk - 1)

    print(x);
}

//Candies

const {EOL} = require('os');

let inp = '';

process.stdin.on('data', c => inp += c);

process.stdin.on('end', () => {
    let lines = inp.split(EOL);

    let t = +lines[0];

    let f = (x) =>  {
    	for(let i = 2; i < 64; i++)  {
    		if(x % (Math.pow(2, i) - 1) == 0)  {
    			return (x / (Math.pow(2, i) - 1));
    		}
    	}
    }

    for(let i = 0; i < t; i++)  {
    	process.stdout.write(f(+lines[i + 1]) + EOL);
    }

    return;
});

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;

    for (let i = 0; i < 60; i++) {
      powers.push(2**i);
    }
    return;
  }

  let n = +d;
  let x = n < 100 ? 1 : Math.floor(n / 3);

  for (let i = 2; i < powers.length; i++) {
    let t = powers[i] - 1;
    if (n % t === 0) {
      ans += `${n / t}\n`;
      break;
    }
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var input = parseInt(readline())
    //var a = readline().split(" ").map(x => parseInt(x))
    while (input--) {
        var n = parseInt(readline())
        var res = 0
        for (var i = 0; i < n; i++) {
            res += Math.pow(2, i)
            if (res != 1 && n % res == 0) {
                var a = n / res
                print(a)
                break;
            }
        }
    }

}

function solve(n) {
  let t = 3;
  while (t <= n) {
    const u = n % t;
    if (u === 0) {
      const x = n / t;
      return x;
    }
    t = t + t + 1;
  }
  throw Error('could not solve the problem');
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    let t = line.trim();
    if (line.length > 0) {
      const n = Number(t);
      const result = solve(n);
      console.log(result);
    }
  }
}

async function processLinesFromStream(rs, pf) {
  const content = [];
  rs.setEncoding("utf-8");
  for await (let chunk of rs) {
    content.push(chunk);
  }
  const lines = content.join('').split(/\n/);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

function solve(n) {
  let t = 3;
  while (t <= n) {
    const u = n % t;
    if (u === 0) {
      const x = n / t;
      return x;
    }
    t = t + t + 1;
  }
  throw Error('could not solve the problem');
}

function main(lines) {
  lines.shift();
  for (const line of lines) {
    const n = Number(line);
    const result = solve(n);
    console.log(result);
  }
}

function trim_line(s) {
  return s.trim();
}

function has_content(s) {
  return (s.length > 0);
}

async function processLinesFromStream(rs, pf) {
  const chunks = [];
  const encoding = 'utf-8';
  rs.setEncoding(encoding);
  for await (let chunk of rs) {
    chunks.push(chunk);
  }
  const empty = '';
  const newline = /\n/;
  const lines = chunks.join(empty)
                      .split(newline)
                      .map(trim_line)
                      .filter(has_content);
  const result = pf(lines);
  return result;
}

processLinesFromStream(process.stdin, main);

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
  inputString = inputString.replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''));
  main();
});

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

let calcMaxSq = (n, a, start) => {
  let res = 1;
  for (let i = n - 1; i > start; i++) {
    if (a[i] === a[start]) {
      res++;
    }
  }
  return res;
}

function solve(n) {
  let nums = [1];
  let k = 1;
  while (true) {
    k *= 2;
    let current = k + nums[nums.length - 1];
    if (n % current === 0) return n / current;
    nums.push(current);
  }
}

function main() {
  const t = parseInt(readLine());
  for (let i = 0; i < t; i++) {
    let n = parseInt(readLine());
    // let a = readLine().split(' ').map((val) => parseInt(val));
    let res = solve(n);
    console.log(res);
  }
  //process.stdout.write("hello: ");
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  var k = 2;
  var flag = true;
  while (flag == true) {
    var x = n / (Math.pow(2, k) - 1);

    if (x == Math.floor(x) && x > 0) {
      print(x);
      flag = false;
    }
    k++;
  }
}

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () => x[y++];

// ************************ Code Start ***************************

function main() {

  var Tc = parseInt(readline());
  for (; Tc--;) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";

function print(x) {
  console.log(x);
}
let x = "", y = 0;

process.stdin.on("data", inputStdin => x += inputStdin);
process.stdin.on("end", () => {
  x = x.split("\n");
  main();
});
function readline() {
  return x[y++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

// Lang: Node.js
'use strict';
let x = '', y = 0;
let print = x => console.log(x);

process.stdin.on('data', inputStdin => x += inputStdin);
process.stdin.on('end', () => { x = x.split('\n'); main(); });
let readline = () =>  x[y++];

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => (inputString += inputStdin));
process.stdin.on("end", () => {inputString = inputString.split("\n");main();});

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

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

'use strict';

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

let inputString = '';
let currentLine = 0;

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

process.stdin.on('end', _ => {
    inputString = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    main();
});

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

function main() {
    let n = parseInt(readLine());
    for (var i = 0; i < n; i++) {
        let t = parseInt(readLine());
        let k = 2;
        while (true) {
            let x = t / (Math.pow(2, k) - 1);
            // console.log('x', x);
            if (Number.isInteger(x) == true) {
                console.log(x);
                break;
            }
            k++;
        }
    }
}

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

rl.on('line', (d) => {
  if (c === 0) {
    c++;

    for (let i = 0; i < 60; i++) {
      powers.push(2**i);
    }
    return;
  }

  let n = +d;
  let x = Math.floor(n / 3);
  let curr = 0;

  for (let i = 0; i < powers.length; i++) {
    curr += powers[i] * x;

    if (curr === n) {
      ans += `${x}\n`;
      break;
    }

    if (curr > n) {
      x++;
      curr = 0;
      i = -1;
    }
  }

  c++;
});

rl.on('close', () => {
  console.log(ans);
});

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
    console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", inputStdin => {
    inputString += inputStdin;
});
process.stdin.on("end", () => {
    inputString = inputString.split("\n");
    main();
});
function readline() {
    return inputString[currentLine++];
}

//-----------main fucntion-----------

function main() {
    var input = parseInt(readline())
    while (input--) {
        var n = parseInt(readline())
        print(n)
    }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) { console.log(x); }

let x = "", y = 0;
process.stdin.on("data", inputStdin => x += inputStdin);
process.stdin.on("end", () => x = x.split("\n"), main());
function readline() { return x[y++]; }

// ************************ Code Start *************************** //

function main() {

  var tc = parseInt(readline());
  for (; tc-- ;) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";

function print(x) {
  console.log(x);
}
let x = "", y = 0;
function readline() {
  return x[y++];
}

// ************************ Code Start ***************************

function main() {

  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => (inputString += inputStdin));
process.stdin.on("end", () => inputString = inputString.split("\n"), main());

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

// ************************ Code Start ***************************

function main() {
  var tc = parseInt(readline());
  while (tc-- > 0) {
    var n = parseInt(readline());
    var m = 2;
    while (n % ((1 << m) - 1) != 0) m++;
    print(n / ((1 << m) - 1));
  }
}

var t = parseInt(readline());
for (var tc = 0; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
}

var t = parseInt(readline());
var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else if (n % 7 == 0) print(n / 7);
  else print(1);
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else print(n);
}

var t = parseInt(readline());
for (var tc = 1; tc <= t; tc++) {
  var n = parseInt(readline());
  if (n % 3 == 0) print(n / 3);
  else print(1);
}

function main()
{
  const testAmount = parseInt(readline());

  const wrapperAmounts = [];
  for (var i = 0; i < testAmount; i++) {
    wrapperAmounts.push(parseInt(readline()));
  }

  for (var i = 0; i < wrapperAmounts.length; i++) {
    for (var k = 2; k <= 29; k++) {
      const x = wrapperAmounts[i] / (Math.pow(2, k) - 1);
      if (x === Math.floor(x)) {
        print(x);
        break;
      }
    }
  }

  return 0;
}
main();


let data = '';
process.stdin.on('data', c => data += c);

function* nextLine() {
	let lines = data.trim().split(/\n/g);
	for(let l of lines){
		yield l.trim();
	}
}
let nl = nextLine();

nl.num = function() {
		return Number(this.next().value);
	};
nl.nums = function() {
		return this.next().value.split(/\s/g).map(Number);
	};
nl.line = function() {
		return this.next().value;
	}

const sol = () => {
	 //using nl.next().value || for(let l of nl)
	let [p, n] = nl.nums();
	let st = new Set();
	let flag = -1;
	for(let i = 0; i < n; i++){
		let num = nl.num()%p;
		if (st.has(num)) {
			flag = i + 1;
			break;
		} else {
			st.add(num);
		}
	}
	console.log(flag);
};

process.stdin.on('end', sol);

;(function () {

	var p = readline().split(' ').map(Number);
	var n = +p[1];
	p = +p[0];

	var h = [];
	for (var i = 0; i < n; i++) {
		var s = +readline();

		if (h[s % p]) {
			print(i + 1);
			return;
		}

		h[s % p] = true;
	}

	print(-1);

}).call(this);

function trim(s) {
	return s.replace(/^\s+|\s+$/gm, '');
}

function tokenize(s) {
	return trim(s).split(/\s+/);
}

function tokenizeIntegers(s) {
	var tokens = tokenize(s);
	for (var i = 0; i < tokens.length; i += 1) {
		tokens[i] = parseInt(tokens[i], 10);
	};
	return tokens;
}

function main() {
	var data = tokenizeIntegers(readline()),
		p = data[0], n = data[1], h = {};
	for (var i = 0; i < n; ++i) {
		var x = parseInt(readline()),
			k = x%p;
		if (h[k]) {
			print(i+1);
			return;
		}
		h[k] = true;
	}
	print(-1);
}

main();

var numbers = []

var firstLine = readline().split(" ").map(Number);
var p = firstLine[0];
var n = firstLine[1];
for(var i = 0; i < n; i ++){
	numbers.push(Number(readline()))
}

var hashes = []
var done = false

for(var i = 0; i <n; i++){
	var hash = numbers[i] % p
	if(hashes.indexOf(hash) !== -1){
		done = true
		print(i + 1)
		break
	}
	else{
		hashes.push(hash)
	}
}

if(!done){
print(-1)
}

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

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

  if (h[+d % p]) {
    ans.push(c);
  }
  else {
    h[+d % p] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }
  else {
    console.log(ans[0]);
  }
});

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

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

  if (h[+d % p]) {
    ans.push(c);
  }
  else {
    h[+d % p] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }

  console.log(ans[0]);
});

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

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

  if (h[+d]) {
    ans.push(c - 1);
  }
  else {
    h[+d] = true;
  }

  c++;
});

rl.on('close', () => {
  if (!ans.length) {
    console.log(-1);
  }

  for (let i = 0; i < ans.length; i++) {
    console.log(ans[i]);
  }
});

var numbers = []

var firstLine = readline().split(" ").map(Number);
var p = firstLine[0];
var n = firstLine[1];
for(var i = 0; i < n; i ++){
	numbers.push(Number(readline()))
}

var hashes = []

for(var i = 0; i <n; i++){
	var hash = numbers[i] % p
	if(hashes.indexOf(hash) !== -1){
		print(i + 1)
		break
	}
	else{
		hashes.push(hash)
	}
}

print(-1)


//var input = readline()

var t = parseInt(readline());
var ar = readline().split(' ').map(x => parseInt(x));

var ok = 0;
ar.sort((a, b) => a - b);

var m = [], n = [];

for(var i=0; i<ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length-1]) {
        n.push(ar[i]);
    } else if (m.length == 0 || ar[i] > m[m.length-1]){
        m.push(ar[i]);
    }
    else {
        ok = 1;
    }
}
print(ok ? 'NO' : "YES" +'\n'+  m.length  +'\n'+  m.join(' ')
                        +'\n'+  n.length  +'\n'+  n.reverse().join(' '));

//

const readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    numbers.sort((x,y) => x-y);
    const increase = [];
    const decrease = [];
    for(let i = 0; i<numbers.length;i++) {
        if (increase.length == 0 ||numbers[i] > increase[increase.length-1]) {
            increase.push(numbers[i])
        } else if (decrease.length == 0 ||numbers[i] > decrease[decrease.length-1]){
            decrease.push(numbers[i]);
        }
        else {
            console.log('No');
            return;
        }
    }
    console.log("Yes");
    console.log(increase.length);
    console.log(increase.join(' '));
    console.log(decrease.length);
    console.log(decrease.reverse().join(' '));
}

readLines(2, doIt);

"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");

function print(x) {
  console.log(x);
}
let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
  inputString += inputStdin;
});
process.stdin.on("end", () => {
  inputString = inputString.split("\n");
  main();
});
function readline() {
  return inputString[currentLine++];
}

// ************************ Code Start ***************************

function main() {

  var t = parseInt(readline());
  var ar = readline().split(' ').map(x => parseInt(x));

  var ok = 0;
  ar.sort((a, b) => a - b);

  var m = [], n = [];
  for (var i = 0; i < ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length - 1]) {
      n.push(ar[i]);
    }
    else if (m.length == 0 || ar[i] > m[m.length - 1]) {
      m.push(ar[i]);
    }
    else ok = 1;
  }
  print(ok ? 'NO' : "YES" + '\n' + m.length + '\n' + m.join(' ')
                          + '\n' + n.length + '\n' + n.reverse().join(' '));

}

var stdin = "";
process.stdin.resume();
process.stdin.setEncoding('ascii');
process.stdin.on('data', function (data) { stdin += data; });
process.stdin.on('end', function () { main(stdin); });

var stdin_row = 0, stdin_rows;
function readLine() { if (!stdin_rows) stdin_rows = stdin.split("\n"); return stdin_rows[stdin_row++]; } // to trim ?
function readLineVals() { return readLine().trim().split(/\s+/); }

const debug = 0
var log = console.log;
var dbg = debug ? console.log : _ => {};

/////////////// ignore above this line ////////////////////

function main(stdin) {
	var n = readLine() * 1;
	var vals = readLineVals();
	if (n!=vals.length)
		throw "input parsing pb "+n+" "+vals;

	vals = vals.sort((a,b)=> a-b);
	incr = [ vals[0] ];
	decr = [];

	for (var i =1; i<vals.length; i++) {
		if (vals[i]!=vals[i-1])
			incr.push(vals[i]);
		else
			// repeated elements are put in decreasing sequence
			decr.push(vals[i]);
	}

	decr = decr.sort((a,b)=> b-a);

	dbg(incr)
	dbg(decr)

	// make sure there is no triplicate
	for (var i =1; i<decr.length; i++) {
		if (decr[i]==decr[i-1]) {
			log("NO");
			return;
		}
	}

	log("YES");
	log(incr.length);
	log(incr.join(" "));
	log(decr.length);
	log(decr.join(" "));

}

//var input = readline()

var t = parseInt(readline())
var ar = readline().split(' ').map(x => parseInt(x))

var ok = 0
ar.sort((a, b) => a - b)

var m = [], n = [];

for(var i=0; i<ar.length; i++) {
    if (n.length == 0 || ar[i] > n[n.length-1]) {
        n.push(ar[i])
    } else if (m.length == 0 || ar[i] > m[m.length-1]){
        m.push(ar[i]);
    }
    else {
        ok = 1;
    }
}
print(ok ? 'NO' : "YES" +'\n'+ m.length  +'\n'+  m.join(' ') +'\n'+
                               n.length  +'\n'+  n.reverse().join(' '));

var t = parseInt(readline());
var ar = readline().split(' ').map(x => parseInt(x));

var ok = 0;
ar.sort((a, b) => a - b);

var m = [], n = [];
for(var i=0; i<ar.length; i++) {
  if (n.length == 0 || ar[i] > n[n.length-1]) {
    n.push(ar[i]);
  }
  else if (m.length == 0 || ar[i] > m[m.length - 1]) {
    m.push(ar[i]);
  }
  else ok = 1;
}
print(ok ? 'NO' : "YES" +'\n'+  m.length  +'\n'+  m.join(' ')
                        +'\n'+  n.length  +'\n'+  n.reverse().join(' '));

const readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

function readLines(number, cb) {
    const lines = [];
    rl.on('line', function(line) {
        lines.push(line);
        if (lines.length === number) {
            rl.close();
            cb(lines);
        }
    });
};

function doIt(lines) {
    const n = parseInt(lines[0]);
    const numbers = lines[1].split(" ").map(x => parseInt(x));
    numbers.sort();
    const increase = [];
    const decrease = [];
    increase.push(numbers[0]);
    let inPrev = numbers[0];
    for(let i = 1; i<numbers.length;i++) {
        if (numbers[i] > inPrev) {
            increase.push(numbers[i])
            inPrev = numbers[i];
        } else {
            if (decrease.length == 0)
                decrease.push(numbers[i]);
            else {
                if (numbers[i] > decrease[decrease.length-1])
                    decrease.push(numbers[i]);
                else {
                    console.log('No');
                    return;
                }
            }
        }
    }
    console.log("Yes");
    console.log(increase.length);
    console.log(increase.join(' '));
    console.log(decrease.length);
    console.log(decrease.reverse().join(' '));
}

readLines(2, doIt);

//var input = readline()

var n = parseInt(readline())
var ar = readline().split(' ').map(x => parseInt(x))

var ok = 0
var dis = ar.sort((a, b) => b - a)
if(dis[0] > 2 ) ok = 1
else ok = 0

if(ok) {
    var duplicates = ar.reduce(function(x, y, z, A) {
        if (A.indexOf(y) !== z && x.indexOf(y) < 0) x.push(y); return x;
    },[]);

    print('YES')
    print(duplicates.length)
    print(duplicates.sort((a, b) => a - b).join(' '))

    var insert = [...new Set(ar)].sort((a, b) => b - a)
    print(insert.length)
    print(insert.join(' '))
}
else {
    print('NO')
}


var input = readline().split(" ").map(i => +i);
var n = input[0];
var m = input[1];
var k = input[2];

var shortestRoad = new Map();
for (var i = 0; i < m; ++i) {
    input = readline().split(" ").map(i => +i);
    var u = input[0];
    var v = input[1];
    var l = input[2];

    if ( !shortestRoad.has(u) ) {
        shortestRoad.set(u, new Map());
    }

    if ( !shortestRoad.has(v) ) {
        shortestRoad.set(v, new Map());
    }

    if ( shortestRoad.get(u).has(v) ) {
        shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l));
    } else {
        shortestRoad.get(u).set(v, l);
    }

    if ( shortestRoad.get(v).has(u) ) {
        shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));
    } else {
        shortestRoad.get(v).set(u, l);
    }
}

var minLength;
if (k) {
    var a = new Set(readline().split(" ").map(i => +i));
    a.forEach(ak => {
        if ( shortestRoad.has(ak) ) {
            shortestRoad.get(ak).forEach( (length, adjCity) => {
                if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {
                    minLength = length;
                }
            });
        }
    });
}

print(minLength || "-1");

'use strict';
const retInt = function(x) { return parseInt(x);};
let e = readline();
while (e !== undefined) {
  let numbers = e.split(" ").map(retInt);
  const n = numbers[0];
  const m = numbers[1];
  const k = numbers[2];

  const adjList = [];
  if (n === 1 || m <= 0) {
     print(-1);
     e.readline();
     continue;
  }

  for (let i = 0; i < m; i++) {
    numbers = readline().split(" ").map(retInt);
    adjList.push(numbers);
  }

  if (k > 0) {
    numbers = readline().split(" ").map(retInt);
    const hm = {};
    for (const num of numbers) {
      hm[num] = true;
    }
    let max = 9999999999;
    let min = 9999999999;
    for (const edge of adjList) {
      const u = edge[0];
      const v = edge[1];
      const l = edge[2];
      if ( (hm[u] && !hm[v]) || (!hm[u] && hm[v]) ) {
        min = l < min ? l : min;
      }
    }
    if (min === max) min = -1;
    print(min);
  } else {
    print('-1');
  }
  e = readline();
}

var input = readline().split(" ").map(i => +i);
var n = input[0];
var m = input[1];
var k = input[2];

var shortestRoad = new Map();
for (var i = 0; i < m; ++i) {
    input = readline().split(" ").map(i => +i);
    var u = input[0];
    var v = input[1];
    var l = input[2];
    if ( !shortestRoad.has(u) ) {
        shortestRoad.set(u, new Map());
    }
    if ( !shortestRoad.has(v) ) {
        shortestRoad.set(v, new Map());
    }
    if ( !shortestRoad.get(u).has(v) ) {
        shortestRoad.get(u).set(v, Math.min(shortestRoad.get(u).get(v), l));
    } else {
        shortestRoad.get(u).set(v, l);
    }
    if ( !shortestRoad.get(v).has(u) ) {
        shortestRoad.get(v).set(u, Math.min(shortestRoad.get(v).get(u), l));
    } else {
        shortestRoad.get(v).set(v, l);
    }
}

var minLength;
if (k) {
    var a = new Set(readline().split(" ").map(i => +i));
    a.forEach(ak => {
        if ( shortestRoad.has(ak) ) {
            shortestRoad.get(ak).forEach( (length, adjCity) => {
                if ( !a.has(adjCity) && ( !minLength || length < minLength ) ) {
                    minLength = length;
                }
            });
        }
    });
}

print(minLength || "-1");