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

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

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

g = A("g")
k = B("k")
f = C("f")
h = A("h")
l = C("l")
b = B("b")
m = A("m")
j = A("j")
a = C("a")

g.v = j
g.w = m
k.s = b
k.r = l
f.s = a
h.v = g
h.w = j
l.s = f
b.s = k
b.r = f
m.v = g
m.w = g
j.v = m
j.w = g
a.s = l
assert b.r.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: A = None
        self.txt = txt

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

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

g = A("g")
k = B("k")
f = C("f")
h = A("h")
l = C("l")
b = B("b")
m = A("m")
j = A("j")
a = C("a")

g.v = j
g.w = m
k.s = b
k.r = l
f.s = a
h.v = g
h.w = j
l.s = f
b.s = k
b.r = f
m.v = g
m.w = g
j.v = m
j.w = g
a.s = l
assert b.r.s.s.s.s.s.s.txt == "f"