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

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

f = A("f")
j = B("j")
g = A("g")
c = A("c")
l = B("l")

f.o = j
j.r = c
j.s = c
g.o = l
c.o = l
l.r = c
l.s = f
assert l.r.o.r.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.r: A = None
        self.s: A = None
        self.txt = txt

f = A("f")
j = B("j")
g = A("g")
c = A("c")
l = B("l")

f.o = j
j.r = c
j.s = c
g.o = l
c.o = l
l.r = c
l.s = f
assert l.r.o.r.o.s.txt == "f"