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

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

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

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

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

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

h.u = f
g.y = f
g.p = h
a.y = f
a.p = h
n.u = f
d.u = g
f.y = a
f.p = d
m.y = a
m.p = k
k.u = a
c.u = f
assert m.p.u.y.y.p.txt == "h"