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

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

l = A("l")
g = B("g")
d = A("d")
c = A("c")
m = A("m")
a = A("a")
f = A("f")
h = B("h")
n = A("n")

l.p = a
l.x = g
g.s = h
d.p = n
d.x = g
c.p = f
c.x = g
m.p = c
m.x = g
a.p = m
a.x = h
f.p = m
f.x = g
h.s = g
n.p = m
n.x = g
assert f.p.x.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.x: B = None
        self.txt = txt

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

l = A("l")
g = B("g")
d = A("d")
c = A("c")
m = A("m")
a = A("a")
f = A("f")
h = B("h")
n = A("n")

l.p = a
l.x = g
g.s = h
d.p = n
d.x = g
c.p = f
c.x = g
m.p = c
m.x = g
a.p = m
a.x = h
f.p = m
f.x = g
h.s = g
n.p = m
n.x = g
assert f.p.x.s.s.s.s.s.txt == "h"