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

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

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

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

i = A("i")
f = B("f")
j = C("j")
g = D("g")

i.o = j
i.q = g
i.t = g
f.x = i
f.y = g
f.q = g
j.x = g
j.q = f
j.v = i
g.q = f
g.x = j
g.z = j
assert f.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.q: D = None
        self.t: D = None
        self.txt = txt

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

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

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

i = A("i")
f = B("f")
j = C("j")
g = D("g")

i.o = j
i.q = g
i.t = g
f.x = i
f.y = g
f.q = g
j.x = g
j.q = f
j.v = i
g.q = f
g.x = j
g.z = j
assert f.x.t.x.txt == "j"