Tossing biased coins in majority voting batches Supposed having $n$ for the number of multiple biased coins, each one having the probability of $p$ for showing heads. By tossing all coins at once, what would be the probability of having more heads than tails? (You could assume that $n$ is an odd number) To solve this part of the problem, I found a similar question which is about the probability of having more heads than tails in tossing one single biased coin for $n$ times. The best answer suggested
$$\sum_{k=0}^{\left\lfloor\frac n2\right\rfloor}{n\choose k}p^{n-k}(1-p)^k$$
But I'm not quite sure if tossing one coin for $n$ times is identical as tossing $n$ coins for one time.
Nevertheless, the problem does not end here. Now, let us assume that we have $m$ batches (again, could be an odd number), each one containing $n$ biased coins. If the majority of coins in a single batch is facing head, the output of the batch will be $1$. Otherwise, it will be either $1$ with the probability of $q$, or $0$ with the probability of $1-q$. The batches themselves form a bigger mega-batch with same laws applied ($1$ as the final output if the majority of the batches are $1$, either $1$ or $0$ with the probabilities $q$ and $q-1$ if the majority of the batches are $0$). In such case, what would be the probability of having a $1$ as the final output of the mega-batch?

P.S.: I've simulated the problem in the following Python code
    import random
    import statistics
    
    def weighted_random(p):
        return 1 if random.random() < p else 0
    
    def C():
        """
        Coin flipping function
        """
        return weighted_random(0.7) # p
    
    
    def B(*args):
        """
        Batch voting function
        """
        majority = statistics.mode([*args])
        if majority == 0:
            return weighted_random(0.1) # q
        return 1
    
    
    def test_megabatch(epochs=1_000):
        sum = 0
    
        for _ in range(epochs):
            c1 = C()
            c2 = C()
            c3 = C()
            c4 = C()
            c5 = C()
            c6 = C()
            c7 = C()
            c8 = C()
            c9 = C()
    
            b1 = B(c1, c2, c3)
            b2 = B(c4, c5, c6)
            b3 = B(c7, c8, c9)
    
            b = B(b1, b2, b3)
    
            sum +=b
       
        return sum
    
    
    print(test_megabatch(10_000) / 10_000) # approximately 0.91

where $n=3$, $m=3$, $p=0.7$ and $q=0.1$ . But I need to actually solve the problem rather than brute-forcing it!
 A: For the first part, it's true that tossing all $n$ coins at once is the same as tossing a single coin $n$ times.  (Imagine that your super-powers include the ability to observe the order in which the coins land.)  Seriously, if we toss the coins one at a time, and let $X_i$ be an indicator random variable that is $1$ if the $i$th toss is heads and $0$ if it is tails, then we want $$\Pr\left(\sum X_i>\frac n2\right)$$.  If we toss all the coins at once, imagine that the coins have been numbered from $1$ to $n$ and define $X_i$ as $1$ if coin number $i$ comes up as head and $0$ if it comes up tails.  Then we want the same probability, and in either case, the $X_i$ are independent Bernoulli r,v,'s with rpobability of success $p$.
Once you have determined that the probability of having more heads than tails in a single batch is $q$, then you can consider a mega batch as tossing $m$ biased coins, each with probability of $q$ of coming up heads.  Use exactly the same formula as before, with $q$ in place of $p$ and $m$ in place of $n$.
A: I finally came up with a general solution. The equation is indeed correct, meaning that tossing $n$ coins for a single time is equivalent to tossing a single coin for $n$ times. Let us define our majority voting equation as a function:
$$f(x, y) = \sum_{k=0}^{\left\lfloor\frac x2\right\rfloor}{x\choose k}y^{x-k}(1-y)^k$$
Also, let $r$ be the probability of having more heads than tails in a single batch:
$$r = f(n,p)$$
Each batch has the probability of $r$ for returning a $1$ on fist try. But failing to do so, it will still have a second chance with the probability of $q$ to return a $1$. That being the case, the probability $s$ of returning a $1$ in either one of the attempts would be:
$$s = p+q(1-p)$$
As saulspatz also mentioned, since the probability for a $1$ being returned from a batch has been determined, we are now able to consider a maga-batch as tossing $m$ biased coins with the probability of $q$ for the majority of them showing heads (or in this case: the majority of batch-outputs being $1$). Henceforth, the same $f$ function could be applied:
$$t = f(m,s)$$
The mega-batch also features a second chance of $q$ on failing to return $1$ at the primary attempt and hence having $u$ as the probability of returning $1$ for the final output which is defined as:
$$u = t+q(1-t) = t(1-q)+q =$$
$$f\Big(m, f(n,p)(1-q) + q\Big).(1-q) + q$$
And here goes the Python implementation:
from math import comb

def f(x,y):
    sigma = 0
    for k in range(int((x+1)/2)):
        sigma += comb(x, k) * y**(x-k) * (1-y)**k
    return sigma

def mega_batch(n, m, p, q):
    return f(m, f(n,p)*(1-q) + q)*(1-q) + q

print(mega_batch(n=3, m=3, p=0.7, q=0.1)) # ≈ 0.9111872806912


P.S. I'd like to appreciate the community of Mathematics Stack Exchange, as well as some friends on Twitter for helping me on this matter.
