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

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

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

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

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

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

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

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

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

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

j.y = h
j.t = g
h.t = j
h.q = g
i.q = h
g.q = j
g.v = m
m.q = b
m.v = g
b.y = h
b.t = m
assert j.y.t.y.t.txt == "j"