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

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

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

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

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

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

k.s = m
c.p = k
i.t = c
i.p = k
g.x = m
g.t = n
g.q = a
g.u = a
a.p = k
m.s = k
n.t = a
n.p = k
assert a.p.s.s.s.txt == "m"