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

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

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

l = A("l")
b = B("b")
i = C("i")
f = A("f")
h = C("h")
m = A("m")
d = A("d")
c = A("c")
g = B("g")

l.r = m
l.u = d
b.p = i
b.s = g
i.x = h
i.z = b
f.r = d
f.u = d
h.x = i
h.z = g
m.r = f
m.u = d
d.r = m
d.u = f
c.r = f
c.u = d
g.p = i
g.s = b
assert g.p.z.p.x.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.u: A = None
        self.txt = txt

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

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

l = A("l")
b = B("b")
i = C("i")
f = A("f")
h = C("h")
m = A("m")
d = A("d")
c = A("c")
g = B("g")

l.r = m
l.u = d
b.p = i
b.s = g
i.x = h
i.z = b
f.r = d
f.u = d
h.x = i
h.z = g
m.r = f
m.u = d
d.r = m
d.u = f
c.r = f
c.u = d
g.p = i
g.s = b
assert g.p.z.p.x.z.p.txt == "i"