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

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

g = A("g")
k = B("k")
j = B("j")
a = B("a")
m = A("m")

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

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

g = A("g")
k = B("k")
j = B("j")
a = B("a")
m = A("m")

g.u = k
k.v = a
k.u = g
j.v = a
j.u = g
a.v = j
a.u = m
m.u = j
assert k.v.u.u.txt == "j"