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

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

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

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

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

g.x = a
g.z = a
m.w = a
c.u = d
c.w = j
c.t = j
a.x = g
d.u = c
d.w = g
d.t = g
j.x = a
j.z = a
assert g.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.z: D = None
        self.txt = txt

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

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

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

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

g.x = a
g.z = a
m.w = a
c.u = d
c.w = j
c.t = j
a.x = g
d.u = c
d.w = g
d.t = g
j.x = a
j.z = a
assert g.x.x.x.x.txt == "g"