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

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

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

n = A("n")
d = B("d")
a = C("a")
e = C("e")
i = A("i")

n.p = i
d.t = n
a.r = e
e.r = a
i.p = n
assert i.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
a = C("a")
e = C("e")
i = A("i")

n.p = i
d.t = n
a.r = e
e.r = a
i.p = n
assert i.p.p.p.p.p.txt == "n"