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

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

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

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

g = A("g")
j = B("j")
h = C("h")
m = D("m")

g.q = m
j.o = m
h.s = g
m.y = h
m.q = g
assert m.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

g = A("g")
j = B("j")
h = C("h")
m = D("m")

g.q = m
j.o = m
h.s = g
m.y = h
m.q = g
assert m.q.q.q.q.txt == "m"