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

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: D = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
a = C("a")
f = D("f")
c = A("c")
i = C("i")

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

class B:
    def __init__(self, txt: str):
        self.x: A = None
        self.q: D = None
        self.txt = txt

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

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

n = A("n")
k = B("k")
a = C("a")
f = D("f")
c = A("c")
i = C("i")

n.z = i
k.x = n
k.q = f
a.z = c
f.p = n
c.z = a
i.z = n
assert a.z.z.z.z.txt == "a"