class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: 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.w: B = None
        self.txt = txt

l = A("l")
a = B("a")
e = C("e")
d = B("d")
h = B("h")
f = A("f")
i = A("i")
g = B("g")

l.p = e
l.y = h
a.x = l
e.w = d
d.x = l
h.x = f
f.p = e
f.y = h
i.p = e
i.y = d
g.x = l
assert h.x.y.x.y.x.p.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.y: 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.w: B = None
        self.txt = txt

l = A("l")
a = B("a")
e = C("e")
d = B("d")
h = B("h")
f = A("f")
i = A("i")
g = B("g")

l.p = e
l.y = h
a.x = l
e.w = d
d.x = l
h.x = f
f.p = e
f.y = h
i.p = e
i.y = d
g.x = l
assert h.x.y.x.y.x.p.w.x.txt == "l"