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

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

f = A("f")
d = B("d")
j = B("j")
a = B("a")
h = A("h")
k = A("k")

f.r = d
d.o = f
d.w = j
j.o = k
j.w = d
a.o = k
a.w = j
h.r = a
k.r = j
assert j.w.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
j = B("j")
a = B("a")
h = A("h")
k = A("k")

f.r = d
d.o = f
d.w = j
j.o = k
j.w = d
a.o = k
a.w = j
h.r = a
k.r = j
assert j.w.o.r.txt == "d"