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

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

g = A("g")
h = B("h")
b = B("b")
j = A("j")

g.z = j
g.t = b
h.w = b
h.v = j
b.w = h
b.v = j
j.z = g
j.t = b
assert b.w.v.z.t.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.t: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
b = B("b")
j = A("j")

g.z = j
g.t = b
h.w = b
h.v = j
b.w = h
b.v = j
j.z = g
j.t = b
assert b.w.v.z.t.txt == "b"