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

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

k = A("k")
b = B("b")
m = B("m")

k.s = b
k.o = m
b.q = m
m.q = b
assert m.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.o: B = None
        self.txt = txt

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

k = A("k")
b = B("b")
m = B("m")

k.s = b
k.o = m
b.q = m
m.q = b
assert m.q.q.q.txt == "b"