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

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

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

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

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

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

b.z = k
b.y = i
h.r = k
k.r = h
i.z = k
i.y = b
assert k.r.r.r.txt == "h"