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

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

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

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

j = A("j")
l = B("l")
c = C("c")
b = D("b")
g = A("g")
a = D("a")
f = D("f")

j.t = c
j.x = g
l.v = a
c.s = g
b.x = c
g.t = c
g.x = j
a.x = c
f.x = c
assert g.t.s.t.s.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.x: A = None
        self.txt = txt

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

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

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

j = A("j")
l = B("l")
c = C("c")
b = D("b")
g = A("g")
a = D("a")
f = D("f")

j.t = c
j.x = g
l.v = a
c.s = g
b.x = c
g.t = c
g.x = j
a.x = c
f.x = c
assert g.t.s.t.s.txt == "g"