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

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

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

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

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

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

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

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

f.v = h
f.w = b
f.p = l
l.x = f
b.x = l
b.y = l
b.s = i
i.v = h
i.w = b
i.p = l
h.v = f
h.w = b
h.p = l
assert l.x.w.y.x.w.txt == "b"