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

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

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

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

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

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

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

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

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

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

e.t = g
e.w = b
b.z = g
b.r = g
g.z = e
g.r = m
m.s = b
m.x = e
m.z = g
assert g.z.t.z.t.txt == "g"