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

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

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

g = A("g")
b = B("b")
i = C("i")
f = C("f")
d = A("d")
c = A("c")
k = B("k")

g.o = d
g.w = b
b.p = i
i.o = f
i.v = f
f.o = i
f.v = i
d.o = g
d.w = k
c.o = d
c.w = b
k.p = i
assert i.v.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.w: B = None
        self.txt = txt

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

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

g = A("g")
b = B("b")
i = C("i")
f = C("f")
d = A("d")
c = A("c")
k = B("k")

g.o = d
g.w = b
b.p = i
i.o = f
i.v = f
f.o = i
f.v = i
d.o = g
d.w = k
c.o = d
c.w = b
k.p = i
assert i.v.o.o.txt == "f"