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

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

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

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

h = A("h")
j = B("j")
n = C("n")
a = D("a")
e = C("e")
f = A("f")

h.p = f
j.q = f
n.q = e
a.s = n
e.q = n
f.p = h
assert e.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
n = C("n")
a = D("a")
e = C("e")
f = A("f")

h.p = f
j.q = f
n.q = e
a.s = n
e.q = n
f.p = h
assert e.q.q.q.txt == "n"