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

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

b = A("b")
c = B("c")
a = A("a")
d = A("d")
l = A("l")

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

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

b = A("b")
c = B("c")
a = A("a")
d = A("d")
l = A("l")

b.q = a
b.o = c
c.z = d
a.q = l
a.o = c
d.q = l
d.o = c
l.q = a
l.o = c
assert a.o.z.q.o.z.txt == "d"