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

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

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

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

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

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

l.o = b
c.p = l
g.p = b
b.o = l
h.p = b
assert g.p.o.o.o.txt == "l"