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

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

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

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

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

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

h.t = j
b.z = j
b.r = j
j.z = b
j.r = b
k.t = b
assert h.t.r.z.txt == "j"