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

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

a = A("a")
n = B("n")
f = B("f")
m = B("m")
g = A("g")
i = B("i")
k = A("k")
j = B("j")

a.v = f
a.p = i
n.x = a
n.w = g
f.x = a
f.w = g
m.x = g
m.w = g
g.v = m
g.p = n
i.x = a
i.w = a
k.v = i
k.p = f
j.x = g
j.w = g
assert f.x.p.x.v.w.v.w.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.p: B = None
        self.txt = txt

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

a = A("a")
n = B("n")
f = B("f")
m = B("m")
g = A("g")
i = B("i")
k = A("k")
j = B("j")

a.v = f
a.p = i
n.x = a
n.w = g
f.x = a
f.w = g
m.x = g
m.w = g
g.v = m
g.p = n
i.x = a
i.w = a
k.v = i
k.p = f
j.x = g
j.w = g
assert f.x.p.x.v.w.v.w.txt == "g"