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

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

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

g = A("g")
c = B("c")
i = C("i")
h = C("h")
e = B("e")
f = B("f")
k = B("k")
a = C("a")
l = C("l")
j = B("j")

g.w = j
c.r = l
i.y = g
i.w = a
h.y = g
h.w = l
e.r = h
f.r = a
k.r = i
a.y = g
a.w = h
l.y = g
l.w = a
j.r = h
assert a.y.w.r.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
i = C("i")
h = C("h")
e = B("e")
f = B("f")
k = B("k")
a = C("a")
l = C("l")
j = B("j")

g.w = j
c.r = l
i.y = g
i.w = a
h.y = g
h.w = l
e.r = h
f.r = a
k.r = i
a.y = g
a.w = h
l.y = g
l.w = a
j.r = h
assert a.y.w.r.y.w.txt == "j"