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

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

m = A("m")
d = B("d")
h = C("h")
k = C("k")
g = A("g")
b = A("b")

m.z = b
m.x = g
d.w = m
h.y = g
k.y = g
g.z = m
g.x = m
b.z = g
b.x = m
assert d.w.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.x: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

m = A("m")
d = B("d")
h = C("h")
k = C("k")
g = A("g")
b = A("b")

m.z = b
m.x = g
d.w = m
h.y = g
k.y = g
g.z = m
g.x = m
b.z = g
b.x = m
assert d.w.x.x.x.txt == "g"