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

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

f = A("f")
n = B("n")
j = B("j")
h = B("h")
g = A("g")

f.y = j
n.q = f
n.x = j
j.q = g
j.x = h
h.q = g
h.x = n
g.y = n
assert j.q.y.q.y.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

f = A("f")
n = B("n")
j = B("j")
h = B("h")
g = A("g")

f.y = j
n.q = f
n.x = j
j.q = g
j.x = h
h.q = g
h.x = n
g.y = n
assert j.q.y.q.y.q.txt == "g"