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

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

e = A("e")
h = B("h")
m = A("m")

e.r = m
h.z = m
h.x = m
m.r = e
assert e.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

e = A("e")
h = B("h")
m = A("m")

e.r = m
h.z = m
h.x = m
m.r = e
assert e.r.r.r.txt == "m"