class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: D = None
        self.z: B = None
        self.o: B = None
        self.y: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
e = C("e")
k = D("k")
m = D("m")
j = B("j")
d = C("d")
f = D("f")
i = C("i")

a.w = j
n.p = a
n.w = a
n.q = j
e.w = k
e.z = n
e.o = j
e.y = j
k.r = f
k.z = n
k.p = d
m.r = f
m.z = n
m.p = i
j.p = a
j.w = a
j.q = n
d.w = f
d.z = n
d.o = j
d.y = j
f.r = k
f.z = j
f.p = i
i.w = m
i.z = j
i.o = j
i.y = j
assert j.q.w.w.q.p.w.q.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: D = None
        self.z: B = None
        self.o: B = None
        self.y: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
e = C("e")
k = D("k")
m = D("m")
j = B("j")
d = C("d")
f = D("f")
i = C("i")

a.w = j
n.p = a
n.w = a
n.q = j
e.w = k
e.z = n
e.o = j
e.y = j
k.r = f
k.z = n
k.p = d
m.r = f
m.z = n
m.p = i
j.p = a
j.w = a
j.q = n
d.w = f
d.z = n
d.o = j
d.y = j
f.r = k
f.z = j
f.p = i
i.w = m
i.z = j
i.o = j
i.y = j
assert j.q.w.w.q.p.w.q.w.w.txt == "j"