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

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

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

f = A("f")
i = B("i")
n = C("n")
d = C("d")
k = C("k")
e = C("e")

f.x = d
i.z = f
n.x = i
n.p = d
d.x = i
d.p = n
k.x = i
k.p = n
e.x = i
e.p = d
assert e.x.z.x.x.z.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

f = A("f")
i = B("i")
n = C("n")
d = C("d")
k = C("k")
e = C("e")

f.x = d
i.z = f
n.x = i
n.p = d
d.x = i
d.p = n
k.x = i
k.p = n
e.x = i
e.p = d
assert e.x.z.x.x.z.x.txt == "d"