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

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

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

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

h.w = j
a.x = h
g.p = m
g.x = j
m.p = c
m.x = d
j.x = h
d.x = h
c.p = m
c.x = d
assert m.p.x.x.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

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

h.w = j
a.x = h
g.p = m
g.x = j
m.p = c
m.x = d
j.x = h
d.x = h
c.p = m
c.x = d
assert m.p.x.x.w.x.txt == "h"