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

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

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

class D:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.v: A = None
        self.z: A = None
        self.txt = txt

g = A("g")
l = B("l")
i = C("i")
f = D("f")
m = B("m")
e = B("e")
a = D("a")

g.q = l
g.o = f
l.r = a
l.q = i
i.z = a
i.w = l
f.s = a
f.w = a
f.v = g
f.z = g
m.r = f
m.q = i
e.r = a
e.q = i
a.s = f
a.w = f
a.v = g
a.z = g
assert m.q.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.o: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.s: D = None
        self.w: D = None
        self.v: A = None
        self.z: A = None
        self.txt = txt

g = A("g")
l = B("l")
i = C("i")
f = D("f")
m = B("m")
e = B("e")
a = D("a")

g.q = l
g.o = f
l.r = a
l.q = i
i.z = a
i.w = l
f.s = a
f.w = a
f.v = g
f.z = g
m.r = f
m.q = i
e.r = a
e.q = i
a.s = f
a.w = f
a.v = g
a.z = g
assert m.q.w.r.txt == "a"