← Home
```go
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var t int
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}

	const MOD = 998244353

	for i := 0; i < t; i++ {
		var s string
		fmt.Fscan(in, &s)

		n := len(s)
		qCount := 0
		for j := 0; j < n; j++ {
			if s[j] == '?' {
				qCount++
			}
		}

		// Calculate 2^qCount % MOD
		pow2 := int64(1)
		base := int64(2)
		exp := qCount
		for exp > 0 {
			if exp%2 == 1 {
				pow2 = (pow2 * base) % MOD
			}
			base = (base * base) % MOD
			exp /= 2
		}

		// A binary string is perfect if it is NOT of the form 011...1
		// We check if s can match the pattern 011...1
		// Pattern: s[0] == '0', s[1...n-1] == '1'
		
		canBeImperfect := true
		
		// Check first char (must be compatible with '0')
		if s[0] == '1' {
			canBeImperfect = false
		}
		
		// Check rest (must be compatible with '1')
		if canBeImperfect {
			for j := 1; j < n; j++ {
				if s[j] == '0' {
					canBeImperfect = false
					break
				}
			}
		}

		ans := pow2
		if canBeImperfect {
			ans = (ans - 1 + MOD) % MOD
		}
		fmt.Fprintln(out, ans)
	}
}
```