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

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

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

n.v = k
h.w = k
h.x = b
l.w = d
l.x = f
m.v = k
f.v = h
d.w = h
d.x = m
k.w = l
k.x = n
b.v = h
assert f.v.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

n.v = k
h.w = k
h.x = b
l.w = d
l.x = f
m.v = k
f.v = h
d.w = h
d.x = m
k.w = l
k.x = n
b.v = h
assert f.v.w.w.w.txt == "d"