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

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

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

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

n = A("n")
g = B("g")
d = C("d")
a = D("a")
e = A("e")
k = A("k")
j = C("j")

n.q = a
g.p = d
d.x = g
d.z = j
d.r = a
a.o = e
a.x = g
a.t = d
a.q = j
e.q = a
k.q = a
j.x = g
j.z = d
j.r = a
assert j.x.p.x.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

n = A("n")
g = B("g")
d = C("d")
a = D("a")
e = A("e")
k = A("k")
j = C("j")

n.q = a
g.p = d
d.x = g
d.z = j
d.r = a
a.o = e
a.x = g
a.t = d
a.q = j
e.q = a
k.q = a
j.x = g
j.z = d
j.r = a
assert j.x.p.x.p.z.txt == "j"