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

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

c = A("c")
l = B("l")
g = B("g")
d = A("d")
a = B("a")

c.q = d
c.p = d
l.s = d
g.s = c
d.q = c
d.p = c
a.s = d
assert a.s.q.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.p: A = None
        self.txt = txt

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

c = A("c")
l = B("l")
g = B("g")
d = A("d")
a = B("a")

c.q = d
c.p = d
l.s = d
g.s = c
d.q = c
d.p = c
a.s = d
assert a.s.q.q.p.txt == "c"