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

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

g = A("g")
k = B("k")
f = B("f")
a = A("a")
l = B("l")
n = A("n")
c = B("c")
j = B("j")

g.z = n
g.y = a
k.y = c
f.y = j
a.z = n
a.y = g
l.y = j
n.z = g
n.y = g
c.y = k
j.y = c
assert g.y.z.y.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: A = None
        self.txt = txt

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

g = A("g")
k = B("k")
f = B("f")
a = A("a")
l = B("l")
n = A("n")
c = B("c")
j = B("j")

g.z = n
g.y = a
k.y = c
f.y = j
a.z = n
a.y = g
l.y = j
n.z = g
n.y = g
c.y = k
j.y = c
assert g.y.z.y.y.z.txt == "n"