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

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

i = A("i")
h = B("h")
f = A("f")
n = B("n")
g = B("g")
c = B("c")
b = B("b")
k = A("k")
a = A("a")

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

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

i = A("i")
h = B("h")
f = A("f")
n = B("n")
g = B("g")
c = B("c")
b = B("b")
k = A("k")
a = A("a")

i.u = c
i.y = b
h.z = g
h.p = i
f.u = g
f.y = h
n.z = h
n.p = f
g.z = c
g.p = k
c.z = n
c.p = a
b.z = h
b.p = f
k.u = c
k.y = b
a.u = b
a.y = h
assert f.y.z.p.y.p.y.z.txt == "g"