We need to read T test cases, each line a binary string. For each string, count the number of occurrences of substring "01". Constraints: string length up to 100k, T up to 50. So total length up to 5M, manageable.
But we need to be careful: factor defined as substring '01'. So we count non-overlapping? Actually "number of times the factor is present" typically means count all occurrences as substrings, possibly overlapping? Since '01' length 2, overlapping doesn't matter because they are length 2 and overlapping would require pattern '01' and then starting at next char: if string is '010', positions 0-1: "01", position 1-2: "10". So no overlapping of same pattern possible because if pattern '01', the next start would be index 1, which would have first char '1' (the second char of the previous pattern) which can't start a new '01' because pattern starts with '0'. So overlapping doesn't happen for pattern '01'. So just count all occurrences where a '0' is immediately followed by '1'.
Thus, for each string, count i from 0 to len-2, if s[i]=='0' and s[i+1]=='1', increment count.
Implement simple solution.
Input: first line integer T, then T lines each a binary string. Possibly there are extra spaces? But description says each line of input is a binary form. So we just read each line. Use sys.stdin to read.
Output: For each test case, print count on a separate line.
Example: Input 1, string "1001010100001". Let's count: positions: 0-1: "10" no, 1-2: "00" no, 2-3: "01" yes, 3-4: "10" no, 4-5: "01" yes, 5-6: "10" no, 6-7: "01" yes, 7-8: "01"? Wait let's list: string: 1 0 0 1 0 1 0 1 0 0 0 0 1? Actually "1001010100001" length? Let's write: 1,0,0,1,0,1,0,1,0,0,0,0,1. So indices: 0:1,1:0,2:0,3:1,4:0,5:1,6:0,7:1,8:0,9:0,10:0,11:0,12:1. Check pairs:
0-1:10 no
1-2:00 no
2-3:01? 2:0,3:1 => yes (1)
3-4:10 no
4-5:01? 4:0,5:1 => yes (2)
5-6:10? 5:1,6:0 => no
6-7:01? 6:0,7:1 => yes (3)
7-8:10? 7:1,8:0 => no
8-9:00? 8:0,9:0 => no
9-10:00 no
10-11:00 no
11-12:01? 11:0,12:1 => yes (4)
So output 4 matches.
Thus solution straightforward.
Edge cases: empty string? But constraint says 1 <= S so at least length 1. But then substring of length 2 may not exist; count 0.
Implementation: read input lines; maybe there are blank lines? Not indicated. We'll robustly read lines skipping empty lines if needed.
Complexity: O(total length).
Now we need to produce answer in required format.
Let's produce Python code:
import sys
def main():
data = sys.stdin.read().split()
# First token is T
if not data:
return
t = int(data[0])
# The next t tokens are strings; if there might be lines with spaces, but binary strings have no spaces.
# Use data[1:1+t]
strings = data[1:1+t]
# In case there are more tokens (like if extra whitespace), but we'll only take t.
# However, reading by split will collapse newlines, which is fine.
for s in strings:
count = 0
# Using simple iteration
for i in range(len(s)-1):
if s[i] == '0' and s[i+1] == '1':
count += 1
print(count)
if name == "main":
main()
Alternatively, use s.count('01')? But careful: s.count('01') counts non-overlapping occurrences, which is exactly what we want. However, Python's count works for substrings and doesn't overlap, and since pattern length 2 and overlapping can't occur, it's safe. But better to be explicit with loop.
But using s.count('01') is simpler: count = s.count('01'). This will count occurrences of the substring in the string, which is what we need. However, is there any catch? For overlapping: In "0101", s.count('01') returns 2? Let's test: "0101".count('01') returns 2 (positions 0-1 and 2-3). Overlap would be starting at index 1 giving "10". So it's fine. So we can use that.
But sometimes in Python, count of substring counts non-overlapping occurrences, but pattern '01' cannot overlap because after a match the next possible start is after the '1', which is index i+2 if the match ends at i+1? Actually if we have "010", s.count('01') finds at index 0: "01", then index 1: starts with '1'? So no overlap. So it's safe. Actually if we had "00101"? It will count both "01" at index 2-3? Wait "00101": indices: 0-1 "00",1-2 "01"? Actually at index 1: '0','1'? "00101": chars:0:0,1:0,2:1,3:0,4:1. So substrings: (0,1):"00", (1,2):"01", (2,3):"10", (3,4):"01". So two occurrences. s.count('01') gives 2. So fine.
Thus count = s.count('01') works.
But careful: The problem might have other factors? No.
Thus code can be simpler.
We'll output each count in separate line.
Edge: T might be large but constraints manageable.
We'll write final answer accordingly.
But the problem statement: "The success of IEEE code-quest depends on number of times the factor is present in a given string.Help core members to find them Factor of string is defined as a substring.In this case it's '01'." So exactly counting occurrences of substring '01'.
Thus final solution:
Read T, then for each string, count occurrences of "01".
Now write full code.
Check for input: maybe there are blank lines after T? Our read split will ignore them.
Test with given example.
Now produce final answer.
Potential pitfalls: If strings have leading/trailing whitespace, split will handle.
All good.
Now produce output as required.
I'll write code with count method.
I'll also include proper reading from sys.stdin.
Make sure to use fast I/O for large input: sys.stdin.read() is fine.
Now produce final answer. ```python
import sys
def main():
data = sys.stdin.read().split()
if not data:
return
t = int(data[0])
strings = data[1:1 + t] # exactly T binary strings
for s in strings:
# count occurrences of "01"
print(s.count('01'))
if name == "main":
main()