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

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

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

g = A("g")
b = B("b")
d = C("d")
h = B("h")
e = A("e")
m = C("m")
a = B("a")
i = B("i")

g.r = e
g.p = e
g.w = d
b.x = h
b.r = d
b.w = g
d.y = g
h.x = a
h.r = d
h.w = g
e.r = g
e.p = g
e.w = d
m.y = e
a.x = i
a.r = d
a.w = e
i.x = h
i.r = m
i.w = g
assert a.w.w.y.p.r.w.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.p: A = None
        self.w: C = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
d = C("d")
h = B("h")
e = A("e")
m = C("m")
a = B("a")
i = B("i")

g.r = e
g.p = e
g.w = d
b.x = h
b.r = d
b.w = g
d.y = g
h.x = a
h.r = d
h.w = g
e.r = g
e.p = g
e.w = d
m.y = e
a.x = i
a.r = d
a.w = e
i.x = h
i.r = m
i.w = g
assert a.w.w.y.p.r.w.y.w.txt == "d"