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

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

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

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

b.x = h
d.p = i
d.x = a
d.v = b
f.w = b
a.w = b
l.p = k
l.x = k
l.v = b
h.p = f
h.x = k
h.v = b
k.w = b
i.w = b
assert i.w.x.x.w.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

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

b.x = h
d.p = i
d.x = a
d.v = b
f.w = b
a.w = b
l.p = k
l.x = k
l.v = b
h.p = f
h.x = k
h.v = b
k.w = b
i.w = b
assert i.w.x.x.w.x.p.txt == "f"