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

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

f = A("f")
g = B("g")
h = A("h")
e = B("e")
c = A("c")
b = A("b")

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

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

f = A("f")
g = B("g")
h = A("h")
e = B("e")
c = A("c")
b = A("b")

f.p = e
g.s = b
h.p = g
e.s = b
c.p = e
b.p = e
assert f.p.s.p.s.txt == "b"