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

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

a = A("a")
g = B("g")
l = B("l")
f = B("f")
j = A("j")
e = A("e")
h = B("h")

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

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

a = A("a")
g = B("g")
l = B("l")
f = B("f")
j = A("j")
e = A("e")
h = B("h")

a.w = h
g.y = j
g.z = a
l.y = j
l.z = e
f.y = e
f.z = e
j.w = g
e.w = h
h.y = e
h.z = j
assert j.w.y.w.y.txt == "j"