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

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

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

f.x = a
f.p = h
b.s = l
b.p = f
g.s = l
g.p = f
h.s = l
h.p = f
a.x = f
a.p = g
l.s = h
l.p = a
assert l.s.s.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: B = None
        self.txt = txt

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

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

f.x = a
f.p = h
b.s = l
b.p = f
g.s = l
g.p = f
h.s = l
h.p = f
a.x = f
a.p = g
l.s = h
l.p = a
assert l.s.s.s.p.txt == "f"