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

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

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

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

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

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

g.q = h
g.u = h
l.p = f
f.p = l
h.q = g
h.u = g
assert g.u.q.u.u.txt == "g"