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

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

i = A("i")
m = B("m")
n = A("n")
j = B("j")

i.u = n
i.v = n
m.u = i
m.v = j
n.u = i
n.v = i
j.u = i
j.v = m
assert i.u.v.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.v: A = None
        self.txt = txt

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

i = A("i")
m = B("m")
n = A("n")
j = B("j")

i.u = n
i.v = n
m.u = i
m.v = j
n.u = i
n.v = i
j.u = i
j.v = m
assert i.u.v.u.v.txt == "i"