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.txt = txt

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

k.r = j
a.z = j
j.z = a
h.r = j
assert h.r.z.z.z.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.txt = txt

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

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