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

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

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

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

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

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

b.q = k
k.t = h
k.s = h
h.t = k
h.s = k
assert b.q.t.t.txt == "k"