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

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

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

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

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

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

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

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

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

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

m.t = g
m.q = c
k.r = m
k.q = a
k.s = c
c.q = g
c.s = m
a.x = c
a.z = g
a.w = k
g.r = m
g.q = a
g.s = c
assert c.q.q.w.txt == "k"