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

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

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

n.p = j
e.y = g
e.v = l
l.p = e
f.p = g
m.p = g
d.y = j
d.v = n
b.p = d
h.p = g
j.y = e
j.v = f
g.y = d
g.v = b
assert b.p.y.v.p.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

n.p = j
e.y = g
e.v = l
l.p = e
f.p = g
m.p = g
d.y = j
d.v = n
b.p = d
h.p = g
j.y = e
j.v = f
g.y = d
g.v = b
assert b.p.y.v.p.y.y.txt == "j"