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.txt = txt

i = A("i")
d = B("d")
j = A("j")
f = B("f")

i.r = d
d.t = i
j.r = d
f.t = i
assert j.r.t.r.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.txt = txt

i = A("i")
d = B("d")
j = A("j")
f = B("f")

i.r = d
d.t = i
j.r = d
f.t = i
assert j.r.t.r.txt == "d"