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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: E = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
m = C("m")
h = D("h")
f = E("f")
g = A("g")

j.p = m
d.u = j
d.v = f
d.q = f
d.t = m
m.q = d
m.s = f
h.o = m
f.r = m
f.z = d
f.w = h
f.u = h
g.p = m
assert h.o.q.q.u.o.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.s: E = None
        self.txt = txt

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

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

j = A("j")
d = B("d")
m = C("m")
h = D("h")
f = E("f")
g = A("g")

j.p = m
d.u = j
d.v = f
d.q = f
d.t = m
m.q = d
m.s = f
h.o = m
f.r = m
f.z = d
f.w = h
f.u = h
g.p = m
assert h.o.q.q.u.o.txt == "m"