class A:
    def __init__(self, txt: str):
        self.z: A = 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.x: D = None
        self.s: B = None
        self.txt = txt

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

k = A("k")
m = B("m")
c = C("c")
i = D("i")
a = A("a")
g = C("g")
d = C("d")

k.z = a
m.p = k
c.x = i
c.s = m
i.q = a
a.z = k
g.x = i
g.s = m
d.x = i
d.s = m
assert i.q.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = 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.x: D = None
        self.s: B = None
        self.txt = txt

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

k = A("k")
m = B("m")
c = C("c")
i = D("i")
a = A("a")
g = C("g")
d = C("d")

k.z = a
m.p = k
c.x = i
c.s = m
i.q = a
a.z = k
g.x = i
g.s = m
d.x = i
d.s = m
assert i.q.z.z.z.txt == "k"