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

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

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

g = A("g")
l = B("l")
b = C("b")
c = B("c")
e = B("e")
k = A("k")
d = C("d")

g.u = c
l.x = d
l.p = c
b.u = d
b.s = k
c.x = b
c.p = e
e.x = b
e.p = l
k.u = e
d.u = b
d.s = g
assert d.s.u.x.s.u.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
b = C("b")
c = B("c")
e = B("e")
k = A("k")
d = C("d")

g.u = c
l.x = d
l.p = c
b.u = d
b.s = k
c.x = b
c.p = e
e.x = b
e.p = l
k.u = e
d.u = b
d.s = g
assert d.s.u.x.s.u.p.x.txt == "d"