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

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

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

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

l.q = f
l.x = b
l.w = i
g.w = i
m.r = b
a.r = b
k.r = f
j.r = f
d.r = l
i.w = g
f.q = b
f.x = l
f.w = i
b.q = f
b.x = l
b.w = i
assert i.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.x: A = None
        self.w: B = None
        self.txt = txt

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

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

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

l.q = f
l.x = b
l.w = i
g.w = i
m.r = b
a.r = b
k.r = f
j.r = f
d.r = l
i.w = g
f.q = b
f.x = l
f.w = i
b.q = f
b.x = l
b.w = i
assert i.w.w.w.w.w.txt == "g"