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

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

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

e = A("e")
b = B("b")
a = C("a")
g = B("g")
d = A("d")
l = B("l")
j = A("j")
m = C("m")
h = B("h")
f = A("f")

e.s = h
e.p = m
b.x = e
b.u = g
b.v = f
a.x = l
g.x = j
g.u = l
g.v = e
d.s = g
d.p = m
l.x = d
l.v = d
l.u = h
j.s = g
j.p = m
m.x = l
h.x = e
h.v = e
h.u = g
f.s = g
f.p = a
assert f.s.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: C = None
        self.txt = txt

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

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

e = A("e")
b = B("b")
a = C("a")
g = B("g")
d = A("d")
l = B("l")
j = A("j")
m = C("m")
h = B("h")
f = A("f")

e.s = h
e.p = m
b.x = e
b.u = g
b.v = f
a.x = l
g.x = j
g.u = l
g.v = e
d.s = g
d.p = m
l.x = d
l.v = d
l.u = h
j.s = g
j.p = m
m.x = l
h.x = e
h.v = e
h.u = g
f.s = g
f.p = a
assert f.s.x.p.txt == "m"