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

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

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

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

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

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

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

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

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

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

j.t = i
j.x = b
j.y = g
i.q = g
i.s = j
h.s = b
b.q = h
b.o = h
b.x = j
b.t = j
g.q = i
g.s = j
assert g.s.t.s.txt == "j"