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

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

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

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

k = A("k")
d = B("d")
g = C("g")
h = D("h")
l = A("l")

k.t = l
k.x = g
d.t = h
d.q = k
d.y = g
d.x = g
g.o = h
g.p = h
g.z = d
g.t = d
h.q = g
l.t = k
l.x = g
assert g.t.x.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.x: C = None
        self.txt = txt

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

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

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

k = A("k")
d = B("d")
g = C("g")
h = D("h")
l = A("l")

k.t = l
k.x = g
d.t = h
d.q = k
d.y = g
d.x = g
g.o = h
g.p = h
g.z = d
g.t = d
h.q = g
l.t = k
l.x = g
assert g.t.x.t.txt == "d"