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

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

m = A("m")
j = B("j")
e = A("e")

m.v = j
j.u = m
j.p = e
e.v = j
assert m.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.u: A = None
        self.p: A = None
        self.txt = txt

m = A("m")
j = B("j")
e = A("e")

m.v = j
j.u = m
j.p = e
e.v = j
assert m.v.u.v.txt == "j"