class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: A = None
        self.txt = txt

e = A("e")
c = B("c")
b = A("b")

e.z = c
c.y = b
c.q = b
b.z = c
assert c.y.z.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: A = None
        self.txt = txt

e = A("e")
c = B("c")
b = A("b")

e.z = c
c.y = b
c.q = b
b.z = c
assert c.y.z.y.txt == "b"