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

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

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

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

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

j.s = m
h.v = j
h.y = j
h.r = i
h.t = i
i.s = m
i.t = m
m.v = h
m.q = i
assert j.s.q.s.v.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

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

j.s = m
h.v = j
h.y = j
h.r = i
h.t = i
i.s = m
i.t = m
m.v = h
m.q = i
assert j.s.q.s.v.txt == "h"