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

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

g = A("g")
h = B("h")
m = A("m")
e = B("e")
b = A("b")

g.s = e
h.q = g
h.t = e
m.s = h
e.q = b
e.t = h
b.s = h
assert e.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
m = A("m")
e = B("e")
b = A("b")

g.s = e
h.q = g
h.t = e
m.s = h
e.q = b
e.t = h
b.s = h
assert e.q.s.q.txt == "g"