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

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

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

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

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

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

h.q = g
h.o = f
g.q = f
l.q = h
f.q = g
f.o = h
assert g.q.o.o.q.txt == "g"