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

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

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

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

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

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

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

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

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