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

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

d = A("d")
j = B("j")
g = B("g")
e = B("e")
f = A("f")

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

d = A("d")
j = B("j")
g = B("g")
e = B("e")
f = A("f")

d.o = g
j.r = g
j.s = d
g.r = e
g.s = d
e.r = j
e.s = d
f.o = e
assert g.r.r.s.txt == "d"