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

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

i = A("i")
m = B("m")
l = A("l")

i.z = m
i.v = l
m.u = l
m.p = l
l.z = m
l.v = i
assert l.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.v: A = None
        self.txt = txt

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

i = A("i")
m = B("m")
l = A("l")

i.z = m
i.v = l
m.u = l
m.p = l
l.z = m
l.v = i
assert l.z.u.z.txt == "m"