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

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

h = A("h")
n = B("n")
m = A("m")
d = B("d")
g = B("g")
b = A("b")
l = A("l")

h.z = g
n.u = m
n.v = l
m.z = d
d.u = b
d.v = h
g.u = b
g.v = l
b.z = n
l.z = g
assert h.z.u.z.u.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

h = A("h")
n = B("n")
m = A("m")
d = B("d")
g = B("g")
b = A("b")
l = A("l")

h.z = g
n.u = m
n.v = l
m.z = d
d.u = b
d.v = h
g.u = b
g.v = l
b.z = n
l.z = g
assert h.z.u.z.u.txt == "m"