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

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

h = A("h")
e = B("e")
g = B("g")
c = B("c")
l = A("l")

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

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

h = A("h")
e = B("e")
g = B("g")
c = B("c")
l = A("l")

h.o = e
e.s = g
e.p = l
g.s = e
g.p = h
c.s = e
c.p = l
l.o = g
assert h.o.s.p.o.s.txt == "g"