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

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

f = A("f")
h = B("h")
n = B("n")
m = A("m")

f.r = n
h.z = f
h.t = n
n.z = f
n.t = h
m.r = h
assert m.r.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: A = None
        self.t: B = None
        self.txt = txt

f = A("f")
h = B("h")
n = B("n")
m = A("m")

f.r = n
h.z = f
h.t = n
n.z = f
n.t = h
m.r = h
assert m.r.z.r.txt == "n"