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

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

f = A("f")
m = B("m")
k = B("k")
b = B("b")

f.u = b
m.p = f
m.v = b
k.p = f
k.v = b
b.p = f
b.v = k
assert m.v.p.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

f = A("f")
m = B("m")
k = B("k")
b = B("b")

f.u = b
m.p = f
m.v = b
k.p = f
k.v = b
b.p = f
b.v = k
assert m.v.p.u.v.txt == "k"