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.x: A = None
        self.txt = txt

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

e = A("e")
c = B("c")
h = C("h")
k = A("k")

e.p = c
c.p = k
c.x = e
h.p = k
k.p = c
assert e.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.x: A = None
        self.txt = txt

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

e = A("e")
c = B("c")
h = C("h")
k = A("k")

e.p = c
c.p = k
c.x = e
h.p = k
k.p = c
assert e.p.p.p.txt == "c"