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

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

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

m = A("m")
l = B("l")
i = C("i")
g = B("g")
j = C("j")
a = A("a")
c = A("c")
n = B("n")
h = A("h")

m.x = j
l.t = n
l.p = n
l.w = a
i.t = a
g.t = n
g.p = n
g.w = m
j.t = c
a.x = i
c.x = j
n.t = l
n.w = h
n.p = g
h.x = j
assert l.t.t.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

m = A("m")
l = B("l")
i = C("i")
g = B("g")
j = C("j")
a = A("a")
c = A("c")
n = B("n")
h = A("h")

m.x = j
l.t = n
l.p = n
l.w = a
i.t = a
g.t = n
g.p = n
g.w = m
j.t = c
a.x = i
c.x = j
n.t = l
n.w = h
n.p = g
h.x = j
assert l.t.t.w.txt == "a"