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

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

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

j = A("j")
h = B("h")
d = C("d")
m = A("m")
c = C("c")
l = B("l")
b = C("b")
g = B("g")
f = B("f")
e = C("e")

j.r = c
h.y = m
h.w = d
d.z = g
d.x = f
m.r = e
c.z = f
c.x = h
l.y = m
l.w = b
b.z = g
b.x = l
g.y = j
g.w = e
f.y = j
f.w = d
e.z = g
e.x = g
assert j.r.z.y.r.x.y.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
d = C("d")
m = A("m")
c = C("c")
l = B("l")
b = C("b")
g = B("g")
f = B("f")
e = C("e")

j.r = c
h.y = m
h.w = d
d.z = g
d.x = f
m.r = e
c.z = f
c.x = h
l.y = m
l.w = b
b.z = g
b.x = l
g.y = j
g.w = e
f.y = j
f.w = d
e.z = g
e.x = g
assert j.r.z.y.r.x.y.r.x.txt == "g"