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

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

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

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

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

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

g.q = h
m.s = h
h.s = m
assert m.s.s.s.txt == "h"