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

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

n = A("n")
m = B("m")
k = B("k")
g = B("g")
j = B("j")
h = A("h")
b = A("b")

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

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

n = A("n")
m = B("m")
k = B("k")
g = B("g")
j = B("j")
h = A("h")
b = A("b")

n.u = j
m.s = b
m.v = b
k.s = n
k.v = n
g.s = h
g.v = n
j.s = h
j.v = b
h.u = j
b.u = j
assert n.u.s.u.txt == "j"