Four different quantum circuit implementations of the same balanced function, computing the majority (see Figure 24) of three bits. (A) Straightforward construction using four gates. (B) The majority is computed in place in the query register, the answer is copied out to the answer register, and the intermediate step is then uncomputed by applying to the query register. (C) is an optimization of A, tuned for as few gates as possible, and (D) is another optimized for few Toffolis followed by few s, generated as part of the list of all 72 possible functions in Appendix A.