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

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

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

b.y = h
a.o = i
j.y = b
g.y = i
c.y = i
h.y = b
i.y = g
assert g.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

b.y = h
a.o = i
j.y = b
g.y = i
c.y = i
h.y = b
i.y = g
assert g.y.y.y.y.txt == "g"