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

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

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

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

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

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

a.r = k
h.z = k
h.r = k
b.r = k
k.z = h
k.r = h
assert h.r.z.z.r.txt == "h"