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

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

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

n.p = i
i.p = h
h.p = f
f.p = n
c.p = i
assert i.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

n.p = i
i.p = h
h.p = f
f.p = n
c.p = i
assert i.p.p.p.txt == "n"