We are given problem description, but it is somewhat unclear. Let's parse.
Problem: Chef decides to distribute fancy stationary among kids. Chef has collection of erasers and pencils. Each kid needs to be given a pencil and eraser. Our job is to help find Chef how many kids can get the stationary and how many min pencils or erasers the chef will need to clear the stock that is left with him.
Input: T test cases. Each test case contains a string made up of E and P. (E for eraser, P for pencil? Actually maybe E stands for Eraser, P stands for Pencil). So the string indicates the sequence? Or perhaps the string represents the inventory: each character is an item? Possibly the string is a sequence of items Chef has? For example, "EPPEP": that contains 2 E's? Let's count: E P P E P -> E's: 2, P's: 3. So Erasers=2, Pencils=3. The output for this test case is "2 1". That is number of kids = 2 (since limited by erasers 2) and min pencils or erasers needed = 1. This means to clear the stock, chef needs either 1 more eraser (to use the extra pencil) or 1 more pencil (to use extra eraser?) But here there are more pencils than erasers, so after giving 2 kids, left with 1 pencil. To "clear the stock", meaning to have zero leftover items, he would need to either get another eraser to match the pencil, or discard the pencil? The phrasing: "how many min pencils or erasers the chef will need to clear the stock that is left with him." That is ambiguous: maybe it means the minimum number of additional items (either pencils or erasers) needed to pair up all remaining items? Or maybe it means the minimum number of items (either pencils or erasers) that will remain after giving as many kids as possible? But output says "2 1" for that case. And example second: "EPPPPEE": let's count: E P P P P E E? Actually string: E P P P P E E? Let's parse: E P P P P E E? Actually "EPPPPEE": characters: E (eraser), P (pencil), P, P, P, E, E. So erasers: count of E = 3 (positions 1,6,7). pencils: count of P = 4 (positions 2,3,4,5). So Erasers=3, Pencils=4. Number of kids = min(3,4)=3. After giving 3 kids, leftover: if we give 3 kids each one eraser and one pencil, we use 3 erasers and 3 pencils. Then leftover: erasers 0? Actually we used 3 erasers and 3 pencils: initial Erasers=3, after using 3, left 0 erasers; Pencils=4, after using 3, left 1 pencil. So leftover stock: 1 pencil. To clear the stock (i.e., to have no items left), Chef would need either 1 eraser to pair with that pencil, or could discard the pencil. The output says "3 1". So again second number is 1. So seems for each test case, answer is (min(CountE, CountP), abs(CountE - CountP)). That yields for first case: min(2,3)=2, diff=1 => output 2 1. Second: min(3,4)=3, diff=1 => output 3 1. Yes.
But wait: is it always the absolute difference? Let's test with equal counts: e.g., "EPEP": E=2, P=2. min=2, diff=0 => output "2 0". That would mean no additional items needed to clear stock. That makes sense: after giving 2 kids, no leftovers.
But let's double-check problem statement: "how many min pencils or erasers the chef will need to clear the stock that is left with him." Could also be interpreted as: after distributing as many kids as possible, there will be leftover items. Chef wants to clear the stock: i.e., to get rid of leftover items. He can either get more pencils or more erasers to pair with leftovers, so that all items are used. The minimum number of additional items he needs is the difference between the counts, because if there are extra pencils, he needs that many erasers; or if extra erasers, need that many pencils. So yes.
Thus solution: for each test case string s, count number of 'E' and number of 'P' (or whichever). Then output min(countE, countP) and abs(countE - countP).
But careful: The string is made up of E and P. But what if there are other characters? Not per constraints.
Edge cases: empty string? Maybe not, but could be length 0? But not specified; likely at least one char? Not needed.
So solution is trivial.
But we must verify the interpretation with the example: matches.
Hence code: read integer T. For each test case, read string s (maybe can have spaces? No, it's a string). Then count. Then print two integers: kids = min(e,p); needed = abs(e-p).
But also need to check potential off-by-one: maybe the "min pencils or erasers needed" means the number of items left after distribution that are either pencils or erasers? Actually it says "how many min pencils or erasers the chef will need to clear the stock that is left with him." The phrase "min pencils or erasers" might be ambiguous: maybe it means the minimum of pencils and erasers left? But the example shows diff. Let's read problem description carefully: "Your job is to help find Chef how many kids can get the stationary and how many min pencils or erasers the chef will need to clear the stock that is left with him." The phrase "how many min pencils or erasers" could be parsed as: "the number of minimal pencils or erasers (i.e., the minimum of the leftover pencils and leftover erasers) that the chef will need to clear the stock." But that would not match example: if leftovers: after giving kids, leftover pencils = max(0, P-E) and leftover erasers = max(0, E-P). The min of those leftovers is 0 if one leftover type is zero. For first case leftover pencils=1, leftover erasers=0 => min=0, not 1. So not matching. So it's the number needed to clear the stock, i.e., to make leftovers zero, which is the difference. Also they say "min pencils or erasers" might mean "minimum number of additional pencils or erasers (you can choose which to acquire) needed to clear the stock." Since you can acquire either pencils or erasers, the minimum number is the difference. Because if you need to clear stock, you can either acquire extra erasers to match extra pencils, or acquire extra pencils to match extra erasers. Either way, you need to acquire a number equal to the difference. So that matches.
Thus answer is diff.
So implement.
Complexity: O(total length) across test cases. Each string length up to maybe large? Not given, but T up to 1000, each string length unknown but probably not huge.
Edge: Could there be other characters like spaces? Probably not.
Implementation: read T, then loop T times, read string s (maybe using cin or input()). In Python: input().strip().
We'll produce output in format: kids needed
We must also handle cases where string might contain newline characters.
Ok.
Thus final solution: For each test case, count e = s.count('E'), p = s.count('P'). kids = min(e,p). diff = abs(e-p). Print kids, diff.
But careful: Are E and P case-sensitive? They are uppercase.
Also note: The example: "EPPEP" counts: E=2, P=3 yields 2 1. Yes.
Potential trap: The string might be like "EP" but without newline. Fine.
Thus final answer.
Let's produce solution in Python.
We'll implement:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data: return
t = int(data[0])
out = []
idx = 1
for _ in range(t):
s = data[idx].strip()
idx += 1
e = s.count('E')
p = s.count('P')
kids = min(e,p)
need = abs(e-p)
out.append(f"{kids} {need}")
sys.stdout.write("\n".join(out))
If we need to handle large input quickly, reading all at once is fine.
That's it.
But wait: There might be nuance: The string is made up of E and P, but perhaps E stands for "Eraser" and P for "Pencil"? Could also be reversed? But the example confirms: with string "EPPEP", if E=eraser, then erasers=2, pencils=3 -> kids=2, need=1. If reversed, then erasers=3, pencils=2 -> kids=2, need=1 also? Let's check: If E=eraser, output matches. If E=pencil? Then "EPPEP": E=3 pencils? Actually if E=pencil, then pencils count = number of E = 2? Wait: "EPPEP" characters: positions:1:E,2:P,3:P,4:E,5:P. If we assume E stands for Eraser, then erasers=2, pencils=3. If we swap: E stands for Pencil, then pencils=2, erasers=3. Then min = 2, diff=1 as well. So both yield same numbers. So no ambiguity. However, the second example: "EPPPPEE": if E=eraser: erasers=3, pencils=4 -> min=3,diff=1. If E=pencil: pencils=3, erasers=4 -> min=3,diff=1. So both produce same. So it's symmetric. So doesn't matter.
Thus answer.
Hence final code.
But I'd like to provide explanation.
Now, let's think about potential extra interpretation: Could "min pencils or erasers" be the minimum number of pencils or erasers left? That would be 0, but output is 1. So no.
One more: Could it be the minimum number of items to purchase to pair the leftovers, which is indeed the difference? Yes.
Thus final solution.
We'll produce answer accordingly.
Now, as the problem expects output as "2 1" etc., just print.
Thus final. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
t = int(data[0])
out_lines = []
idx = 1
for _ in range(t):
s = data[idx]
idx += 1
e = s.count('E')
p = s.count('P')
kids = min(e, p)
need = abs(e - p)
out_lines.append(f"{kids} {need}")
sys.stdout.write("\n".join(out_lines))
if name == "main":
solve()