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

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

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

n = A("n")
j = B("j")
b = C("b")
e = A("e")
k = A("k")

n.p = k
n.q = b
j.x = b
j.q = k
b.q = n
e.p = n
e.q = b
k.p = n
k.q = b
assert b.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.q: C = None
        self.txt = txt

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

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

n = A("n")
j = B("j")
b = C("b")
e = A("e")
k = A("k")

n.p = k
n.q = b
j.x = b
j.q = k
b.q = n
e.p = n
e.q = b
k.p = n
k.q = b
assert b.q.q.q.q.txt == "b"