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

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

b = A("b")
h = B("h")
i = A("i")
j = B("j")
n = B("n")
d = A("d")
l = B("l")
a = A("a")

b.v = a
b.w = h
h.p = i
i.v = a
i.w = j
j.p = a
n.p = a
d.v = b
d.w = j
l.p = d
a.v = d
a.w = n
assert b.w.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.w: B = None
        self.txt = txt

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

b = A("b")
h = B("h")
i = A("i")
j = B("j")
n = B("n")
d = A("d")
l = B("l")
a = A("a")

b.v = a
b.w = h
h.p = i
i.v = a
i.w = j
j.p = a
n.p = a
d.v = b
d.w = j
l.p = d
a.v = d
a.w = n
assert b.w.p.v.txt == "a"