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

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

a = A("a")
j = B("j")
g = B("g")

a.r = j
j.t = a
j.w = a
g.t = a
g.w = a
assert j.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

a = A("a")
j = B("j")
g = B("g")

a.r = j
j.t = a
j.w = a
g.t = a
g.w = a
assert j.w.r.w.txt == "a"