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

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

h = A("h")
a = B("a")
j = A("j")
i = A("i")
f = A("f")
c = B("c")
m = A("m")

h.x = j
a.v = i
a.o = c
j.x = m
i.x = j
f.x = i
c.v = i
c.o = a
m.x = j
assert j.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

h = A("h")
a = B("a")
j = A("j")
i = A("i")
f = A("f")
c = B("c")
m = A("m")

h.x = j
a.v = i
a.o = c
j.x = m
i.x = j
f.x = i
c.v = i
c.o = a
m.x = j
assert j.x.x.x.x.txt == "j"