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

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

l = A("l")
d = B("d")
a = B("a")
f = B("f")
e = A("e")
h = B("h")

l.s = d
l.p = e
d.q = e
d.p = l
a.q = l
a.p = e
f.q = l
f.p = l
e.s = d
e.p = l
h.q = l
h.p = l
assert a.p.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.p: A = None
        self.txt = txt

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

l = A("l")
d = B("d")
a = B("a")
f = B("f")
e = A("e")
h = B("h")

l.s = d
l.p = e
d.q = e
d.p = l
a.q = l
a.p = e
f.q = l
f.p = l
e.s = d
e.p = l
h.q = l
h.p = l
assert a.p.p.s.p.txt == "l"