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

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

j = A("j")
d = B("d")
g = B("g")
h = A("h")
e = A("e")
a = A("a")
k = A("k")
c = A("c")

j.r = a
d.o = g
d.v = e
g.o = d
g.v = h
h.r = j
e.r = k
a.r = c
k.r = a
c.r = k
assert h.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

j = A("j")
d = B("d")
g = B("g")
h = A("h")
e = A("e")
a = A("a")
k = A("k")
c = A("c")

j.r = a
d.o = g
d.v = e
g.o = d
g.v = h
h.r = j
e.r = k
a.r = c
k.r = a
c.r = k
assert h.r.r.r.r.txt == "k"