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

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

m = A("m")
a = B("a")
h = A("h")
j = A("j")
g = B("g")
e = A("e")

m.w = e
a.z = g
a.w = h
h.w = j
j.w = m
g.z = a
g.w = j
e.w = j
assert j.w.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

m = A("m")
a = B("a")
h = A("h")
j = A("j")
g = B("g")
e = A("e")

m.w = e
a.z = g
a.w = h
h.w = j
j.w = m
g.z = a
g.w = j
e.w = j
assert j.w.w.w.w.w.w.txt == "j"