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

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

j = A("j")
l = B("l")
m = A("m")
i = A("i")
k = B("k")
d = B("d")
g = A("g")

j.v = m
j.u = i
l.o = k
m.v = g
m.u = j
i.v = j
i.u = j
k.o = l
d.o = l
g.v = m
g.u = j
assert m.v.v.u.v.txt == "
class A:
    def __init__(self, txt: str):
        self.v: A = None
        self.u: A = None
        self.txt = txt

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

j = A("j")
l = B("l")
m = A("m")
i = A("i")
k = B("k")
d = B("d")
g = A("g")

j.v = m
j.u = i
l.o = k
m.v = g
m.u = j
i.v = j
i.u = j
k.o = l
d.o = l
g.v = m
g.u = j
assert m.v.v.u.v.txt == "m"