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

l = A("l")
d = B("d")
k = C("k")

l.p = d
d.p = l
d.x = l
k.p = d
assert k.p.x.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: B = None
        self.txt = txt

l = A("l")
d = B("d")
k = C("k")

l.p = d
d.p = l
d.x = l
k.p = d
assert k.p.x.p.txt == "d"