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

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

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

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

h = A("h")
g = B("g")
m = C("m")
f = D("f")
j = D("j")
k = C("k")
d = B("d")
a = C("a")
c = B("c")
l = D("l")

h.q = a
g.r = h
g.w = h
g.o = d
g.z = j
m.p = h
f.w = d
j.w = d
k.p = h
d.r = h
d.w = h
d.o = g
d.z = l
a.p = h
c.r = h
c.w = h
c.o = g
c.z = f
l.w = c
assert j.w.o.o.z.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

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

h = A("h")
g = B("g")
m = C("m")
f = D("f")
j = D("j")
k = C("k")
d = B("d")
a = C("a")
c = B("c")
l = D("l")

h.q = a
g.r = h
g.w = h
g.o = d
g.z = j
m.p = h
f.w = d
j.w = d
k.p = h
d.r = h
d.w = h
d.o = g
d.z = l
a.p = h
c.r = h
c.w = h
c.o = g
c.z = f
l.w = c
assert j.w.o.o.z.w.o.txt == "g"