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

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

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

f = A("f")
d = B("d")
e = C("e")
i = C("i")
b = A("b")
l = B("l")
a = C("a")

f.w = b
d.r = l
e.r = a
e.y = f
i.r = e
i.y = b
b.w = f
l.r = d
a.r = i
a.y = b
assert e.y.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

f = A("f")
d = B("d")
e = C("e")
i = C("i")
b = A("b")
l = B("l")
a = C("a")

f.w = b
d.r = l
e.r = a
e.y = f
i.r = e
i.y = b
b.w = f
l.r = d
a.r = i
a.y = b
assert e.y.w.w.txt == "f"