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

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

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

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

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

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

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

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

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

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

a.q = h
a.o = f
j.q = m
j.v = h
j.t = b
d.t = f
b.r = i
b.z = h
m.q = h
m.o = f
h.t = i
i.q = a
i.v = d
i.t = b
f.q = a
f.v = h
f.t = b
e.q = h
e.o = j
c.r = f
c.z = h
assert e.q.t.t.r.q.txt == "a"