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

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

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

n = A("n")
d = B("d")
j = C("j")

n.p = j
d.p = n
j.p = n
j.x = n
assert d.p.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
j = C("j")

n.p = j
d.p = n
j.p = n
j.x = n
assert d.p.p.x.txt == "n"