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

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

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

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

c = A("c")
b = B("b")
n = C("n")
m = D("m")
d = C("d")
i = D("i")
h = A("h")
j = D("j")
f = C("f")

c.q = b
c.o = d
b.z = d
b.t = c
b.u = m
b.x = m
n.z = c
m.t = i
d.z = c
i.t = j
h.q = b
h.o = d
j.t = i
f.z = h
assert b.z.z.o.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.o: C = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
n = C("n")
m = D("m")
d = C("d")
i = D("i")
h = A("h")
j = D("j")
f = C("f")

c.q = b
c.o = d
b.z = d
b.t = c
b.u = m
b.x = m
n.z = c
m.t = i
d.z = c
i.t = j
h.q = b
h.o = d
j.t = i
f.z = h
assert b.z.z.o.z.q.txt == "b"