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

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

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

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

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

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

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