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

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

l = A("l")
n = B("n")
d = A("d")

l.o = n
l.y = d
n.p = d
n.q = l
d.o = n
d.y = l
assert l.o.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.y: A = None
        self.txt = txt

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

l = A("l")
n = B("n")
d = A("d")

l.o = n
l.y = d
n.p = d
n.q = l
d.o = n
d.y = l
assert l.o.p.y.txt == "l"