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

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

g = A("g")
n = B("n")
l = A("l")
f = A("f")
h = A("h")
e = A("e")
c = B("c")

g.y = c
g.p = h
n.u = e
n.s = c
l.y = n
l.p = e
f.y = n
f.p = g
h.y = c
h.p = e
e.y = n
e.p = f
c.u = h
c.s = n
assert f.y.u.p.y.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: A = None
        self.txt = txt

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

g = A("g")
n = B("n")
l = A("l")
f = A("f")
h = A("h")
e = A("e")
c = B("c")

g.y = c
g.p = h
n.u = e
n.s = c
l.y = n
l.p = e
f.y = n
f.p = g
h.y = c
h.p = e
e.y = n
e.p = f
c.u = h
c.s = n
assert f.y.u.p.y.u.p.txt == "f"