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

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

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

g = A("g")
c = B("c")
n = C("n")
l = B("l")
b = B("b")
a = A("a")
j = C("j")
f = C("f")

g.x = l
c.w = f
n.r = j
l.w = n
b.w = f
a.x = b
j.r = n
f.r = j
assert b.w.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
n = C("n")
l = B("l")
b = B("b")
a = A("a")
j = C("j")
f = C("f")

g.x = l
c.w = f
n.r = j
l.w = n
b.w = f
a.x = b
j.r = n
f.r = j
assert b.w.r.r.r.txt == "j"