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

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

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

g = A("g")
h = B("h")
n = C("n")
c = B("c")
j = B("j")

g.x = j
h.s = g
h.t = n
n.y = c
n.r = g
c.s = g
c.t = n
j.s = g
j.t = n
assert g.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
n = C("n")
c = B("c")
j = B("j")

g.x = j
h.s = g
h.t = n
n.y = c
n.r = g
c.s = g
c.t = n
j.s = g
j.t = n
assert g.x.s.x.txt == "j"