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

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

g = A("g")
e = B("e")
k = B("k")
m = A("m")

g.u = k
e.q = g
e.p = m
k.q = g
k.p = m
m.u = k
assert e.q.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

g = A("g")
e = B("e")
k = B("k")
m = A("m")

g.u = k
e.q = g
e.p = m
k.q = g
k.p = m
m.u = k
assert e.q.u.p.u.txt == "k"