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

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

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

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

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

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

g.y = a
b.r = j
a.r = j
j.r = a
assert j.r.r.r.txt == "a"