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

a = A("a")
d = B("d")
g = B("g")
b = A("b")
i = B("i")
h = A("h")
j = A("j")

a.r = d
d.t = j
g.t = a
b.r = g
i.t = h
h.r = d
j.r = g
assert b.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

a = A("a")
d = B("d")
g = B("g")
b = A("b")
i = B("i")
h = A("h")
j = A("j")

a.r = d
d.t = j
g.t = a
b.r = g
i.t = h
h.r = d
j.r = g
assert b.r.t.r.txt == "d"