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

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

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

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

f.w = a
k.z = i
k.y = b
b.r = f
d.r = f
i.z = k
i.y = b
a.w = j
j.w = a
assert b.r.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.z: B = None
        self.y: C = None
        self.txt = txt

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

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

f.w = a
k.z = i
k.y = b
b.r = f
d.r = f
i.z = k
i.y = b
a.w = j
j.w = a
assert b.r.w.w.txt == "j"