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

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

i = A("i")
d = B("d")
l = A("l")
b = B("b")

i.q = l
i.z = l
d.o = b
l.q = i
l.z = i
b.o = d
assert d.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.txt = txt

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

i = A("i")
d = B("d")
l = A("l")
b = B("b")

i.q = l
i.z = l
d.o = b
l.q = i
l.z = i
b.o = d
assert d.o.o.o.txt == "b"