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

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

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

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

m = A("m")
g = B("g")
a = C("a")
c = D("c")
b = C("b")

m.t = b
m.s = g
m.q = a
g.p = b
a.q = c
a.p = m
a.r = b
a.z = b
c.p = g
b.q = c
b.p = m
b.r = a
b.z = a
assert m.t.z.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.s: B = None
        self.q: C = None
        self.txt = txt

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

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

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

m = A("m")
g = B("g")
a = C("a")
c = D("c")
b = C("b")

m.t = b
m.s = g
m.q = a
g.p = b
a.q = c
a.p = m
a.r = b
a.z = b
c.p = g
b.q = c
b.p = m
b.r = a
b.z = a
assert m.t.z.q.p.txt == "g"