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

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

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

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

g = A("g")
k = B("k")
m = C("m")
a = D("a")
j = B("j")

g.z = k
g.o = j
k.o = a
k.q = m
m.u = j
a.q = g
j.o = a
j.q = m
assert m.u.q.u.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.o: B = None
        self.txt = txt

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

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

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

g = A("g")
k = B("k")
m = C("m")
a = D("a")
j = B("j")

g.z = k
g.o = j
k.o = a
k.q = m
m.u = j
a.q = g
j.o = a
j.q = m
assert m.u.q.u.o.q.txt == "g"