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

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

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

j = A("j")
f = B("f")
g = C("g")
c = B("c")
d = C("d")
l = B("l")

j.q = l
j.t = d
j.x = g
f.o = j
f.x = j
g.y = d
c.o = j
c.x = j
d.y = g
l.o = j
l.x = j
assert d.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.x: C = None
        self.txt = txt

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

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

j = A("j")
f = B("f")
g = C("g")
c = B("c")
d = C("d")
l = B("l")

j.q = l
j.t = d
j.x = g
f.o = j
f.x = j
g.y = d
c.o = j
c.x = j
d.y = g
l.o = j
l.x = j
assert d.y.y.y.y.y.y.txt == "d"