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

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

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

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

m = A("m")
e = B("e")
f = C("f")
n = D("n")
d = A("d")
b = C("b")
g = D("g")

m.t = g
e.x = b
e.z = m
f.q = g
n.r = d
n.q = e
d.t = n
b.q = n
g.r = m
g.q = e
assert n.q.z.t.q.z.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

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

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

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

m = A("m")
e = B("e")
f = C("f")
n = D("n")
d = A("d")
b = C("b")
g = D("g")

m.t = g
e.x = b
e.z = m
f.q = g
n.r = d
n.q = e
d.t = n
b.q = n
g.r = m
g.q = e
assert n.q.z.t.q.z.t.q.txt == "e"