using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); static string[] SList(long n) => Enumerable.Repeat(0, (int)n).Select(_ => ReadLine()).ToArray(); public static void Main() { Solve(); } static void Solve() { var t = NN; var ans = new long[t]; for (var u = 0; u < t; ++u) { var l = ReadLine().Split(); var n = long.Parse(l[0]); ans[u] = Math.Max(0, n - 999); var sx1000 = int.Parse(l[1].Replace(".", "")); for (var i = 1; i < 1000 && i <= n; ++i) { var totalx1000 = i * sx1000; var total = (totalx1000 + (1000 - totalx1000 % 1000) % 1000) / 1000; if (total * 1000 / i == sx1000) ++ans[u]; } } WriteLine(string.Join(" ", ans)); } }