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

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

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

g = A("g")
h = B("h")
b = C("b")
f = A("f")
j = B("j")
k = B("k")
i = A("i")

g.w = i
g.v = b
h.r = f
b.w = h
b.x = k
f.w = g
f.v = b
j.r = f
k.r = f
i.w = g
i.v = b
assert b.w.r.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.v: C = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
b = C("b")
f = A("f")
j = B("j")
k = B("k")
i = A("i")

g.w = i
g.v = b
h.r = f
b.w = h
b.x = k
f.w = g
f.v = b
j.r = f
k.r = f
i.w = g
i.v = b
assert b.w.r.v.txt == "b"