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

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

l = A("l")
i = B("i")
c = C("c")

l.p = c
i.p = l
i.x = l
c.y = i
assert c.y.x.p.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.x: A = None
        self.txt = txt

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

l = A("l")
i = B("i")
c = C("c")

l.p = c
i.p = l
i.x = l
c.y = i
assert c.y.x.p.txt == "c"