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

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

g = A("g")
l = B("l")
h = B("h")

g.q = h
g.w = l
l.z = h
h.z = l
assert g.q.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.w: B = None
        self.txt = txt

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

g = A("g")
l = B("l")
h = B("h")

g.q = h
g.w = l
l.z = h
h.z = l
assert g.q.z.z.txt == "h"