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

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

h = A("h")
n = B("n")
f = B("f")
e = A("e")
i = B("i")

h.r = e
n.s = i
f.s = n
e.r = h
i.s = n
assert i.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

h = A("h")
n = B("n")
f = B("f")
e = A("e")
i = B("i")

h.r = e
n.s = i
f.s = n
e.r = h
i.s = n
assert i.s.s.s.s.s.txt == "n"