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

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

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

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

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

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

n.v = j
n.y = b
b.u = n
g.u = j
i.u = n
j.v = n
j.y = i
m.u = j
assert i.u.v.y.txt == "i"