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

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

c = A("c")
a = B("a")
k = B("k")

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

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

c = A("c")
a = B("a")
k = B("k")

c.o = k
c.z = k
a.q = k
k.q = a
assert a.q.q.q.txt == "k"