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

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

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

n.r = h
e.p = h
m.p = n
h.r = n
assert h.r.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.p: A = None
        self.txt = txt

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

n.r = h
e.p = h
m.p = n
h.r = n
assert h.r.r.r.r.txt == "h"