✅ Simple Java Solution
CODE\nJava []\nclass Solution {\n    class Pair {\n        TreeNode node;\n        int level;\n        Pair(TreeNode n, int l) {\n            node = n;\n       
## **CODE**\n```Java []\nclass Solution {\n    class Pair {\n        TreeNode node;\n        int level;\n        Pair(TreeNode n, int l) {\n            node = n;\n            level = l;\n        }\n    }\n    \n    public int[] treeQueries(TreeNode root, int[] queries) {\n        Map<Integer, Pair> valueMap = new HashMap<>();\n        Map<Integer, Integer> levelMap = new HashMap<>();\n        \n        Queue<TreeNode> bfs = new LinkedList<>();\n        bfs.add(root);\n        \n        int levelCount=0, size = 0;\n        while(!bfs.isEmpty()) {\n            size = bfs.size();\n            levelMap.put(levelCount, size);\n            \n            while(size-- > 0) {\n                TreeNode top = bfs.remove();\n                valueMap.put(top.val, new Pair(top, levelCount));\n                if(top.left != null) bfs.add(top.left);\n                if(top.right != null) bfs.add(top.right);\n            }\n            levelCount++;\n        }\n        levelMap.put(levelCount, 0);\n        \n        int n = queries.length, i = 0;\n        int res[] = new int[n];\n        for(int query : queries) {\n            Pair p = valueMap.get(query);\n            TreeNode curr = p.node;\n            \n            if(levelMap.get(p.level) == 1) {\n                res[i++] = p.level-1;\n                continue;\n            }\n            \n            bfs.clear();\n            bfs.add(curr);\n            int currLevel = p.level;\n            boolean flag = true;\n            \n            while(!bfs.isEmpty()) {\n                int nodeCounts = levelMap.get(currLevel+1);\n                size = bfs.size();\n                \n                while(size-- > 0) {\n                    TreeNode top = bfs.remove();\n                    if(top.left != null) {\n                        bfs.add(top.left);\n                        nodeCounts--;\n                    }\n                    if(top.right != null) {\n                        bfs.add(top.right);\n                        nodeCounts--;\n                    }\n                }\n                \n                if(nodeCounts == 0) {\n                    res[i++] = currLevel;\n                    flag=false;\n                    break;\n                }\n                currLevel++;\n            }\n            \n            if(flag) {\n                res[i++] = levelCount-1;\n            }\n        }\n        \n        return res;\n    }\n}\n```
['Breadth-First Search', 'Java']