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

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

a = A("a")
k = B("k")
h = B("h")
i = B("i")
b = A("b")

a.u = h
a.q = k
k.s = b
h.s = b
i.s = b
b.u = h
b.q = i
assert k.s.u.s.u.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.q: B = None
        self.txt = txt

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

a = A("a")
k = B("k")
h = B("h")
i = B("i")
b = A("b")

a.u = h
a.q = k
k.s = b
h.s = b
i.s = b
b.u = h
b.q = i
assert k.s.u.s.u.s.txt == "b"