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

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

class C:
    def __init__(self, txt: str):
        self.o: D = None
        self.v: B = None
        self.p: C = None
        self.t: E = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
n = C("n")
m = D("m")
f = E("f")
i = C("i")

d.q = j
d.u = m
j.x = i
j.z = d
n.o = m
n.v = j
n.p = i
n.t = f
m.p = j
m.t = j
m.r = j
m.w = j
m.x = i
f.p = j
f.x = j
i.o = m
i.v = j
i.p = n
i.t = f
assert j.z.q.z.q.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.u: D = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.o: D = None
        self.v: B = None
        self.p: C = None
        self.t: E = None
        self.txt = txt

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

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

d = A("d")
j = B("j")
n = C("n")
m = D("m")
f = E("f")
i = C("i")

d.q = j
d.u = m
j.x = i
j.z = d
n.o = m
n.v = j
n.p = i
n.t = f
m.p = j
m.t = j
m.r = j
m.w = j
m.x = i
f.p = j
f.x = j
i.o = m
i.v = j
i.p = n
i.t = f
assert j.z.q.z.q.z.txt == "d"