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

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

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

e.w = d
e.v = m
d.t = e
d.p = e
m.w = d
m.v = e
assert d.p.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.v: A = None
        self.txt = txt

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

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

e.w = d
e.v = m
d.t = e
d.p = e
m.w = d
m.v = e
assert d.p.v.v.txt == "e"