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

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

h = A("h")
j = B("j")
c = B("c")
a = A("a")
l = A("l")

h.o = j
h.p = j
j.x = a
c.x = h
a.o = j
a.p = c
l.o = c
l.p = c
assert l.p.x.o.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.p: B = None
        self.txt = txt

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

h = A("h")
j = B("j")
c = B("c")
a = A("a")
l = A("l")

h.o = j
h.p = j
j.x = a
c.x = h
a.o = j
a.p = c
l.o = c
l.p = c
assert l.p.x.o.x.txt == "a"