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

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

g = A("g")
k = B("k")
n = C("n")
j = D("j")
m = A("m")
l = C("l")
f = C("f")

g.q = l
k.u = j
n.t = m
j.u = l
j.s = n
j.x = k
j.p = k
m.q = n
l.t = m
f.t = m
assert l.t.q.t.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

g = A("g")
k = B("k")
n = C("n")
j = D("j")
m = A("m")
l = C("l")
f = C("f")

g.q = l
k.u = j
n.t = m
j.u = l
j.s = n
j.x = k
j.p = k
m.q = n
l.t = m
f.t = m
assert l.t.q.t.q.t.q.txt == "n"